in cloudformation/external-slurmdbd/external_slurmdbd/external_slurmdbd_stack.py [0:0]
def _add_external_slurmdbd_launch_template(self):
# Define a CfnParameter for the AMI ID
# This AMI should be Parallel Cluster AMI, which has installed Slurm and related software
ami_id_param = CfnParameter(
self, "AmiId", type="AWS::EC2::Image::Id", description="The AMI id for the EC2 instance."
)
instance_type_param = CfnParameter(
self,
"InstanceType",
type="String",
description="The instance type for the EC2 instance",
)
key_name_param = CfnParameter(
self,
"KeyName",
type="AWS::EC2::KeyPair::KeyName",
description="The SSH key name to access the instance (for management purposes only)",
)
self.slurmdbd_private_ip = CfnParameter(
self,
"PrivateIp",
type="String",
description="Static private IP address + prefix to assign to the slurmdbd instance",
)
self.slurmdbd_private_prefix = CfnParameter(
self,
"PrivatePrefix",
type="String",
description="Subnet prefix to assign with the private IP to the slurmdbd instance",
)
dbms_client_sg_id = CfnParameter(
self, "DBMSClientSG", type="AWS::EC2::SecurityGroup::Id", description="DBMS Client Security Group Id"
)
launch_template_data = ec2.CfnLaunchTemplate.LaunchTemplateDataProperty(
key_name=key_name_param.value_as_string,
image_id=ami_id_param.value_as_string,
instance_type=instance_type_param.value_as_string,
user_data=Fn.base64(
Fn.sub(
get_user_data_content("../resources/user_data.sh"),
{
**{
"CustomCookbookUrl": self.custom_cookbook_url_param.value_as_string,
"StackName": Aws.STACK_NAME,
"Region": self.region,
"PrivateIp": self.slurmdbd_private_ip.value_as_string,
"SubnetPrefix": self.slurmdbd_private_prefix.value_as_string,
},
},
)
),
iam_instance_profile=ec2.CfnLaunchTemplate.IamInstanceProfileProperty(name=self._instance_profile),
network_interfaces=[
ec2.CfnLaunchTemplate.NetworkInterfaceProperty(
device_index=0,
groups=[
self._ssh_server_sg.ref,
self._slurmdbd_server_sg.ref,
dbms_client_sg_id.value_as_string,
],
subnet_id=self.subnet_id.value_as_string,
),
],
metadata_options=ec2.CfnLaunchTemplate.MetadataOptionsProperty(
http_tokens="required",
),
)
launch_template = ec2.CfnLaunchTemplate(self, "LaunchTemplate", launch_template_data=launch_template_data)
self._cfn_init_config = self._add_cfn_init_config()
launch_template.add_metadata("AWS::CloudFormation::Init", self._cfn_init_config)
return launch_template