I'm attempting to specify an EC2 launch template using CDK.
So far my template declaration looks like this:
let launch_template = new ec2.LaunchTemplate(
this,
'MyLaunchTemplate',
{
instanceType: params.instanceType,
machineImage: ec2.MachineImage.latestAmazonLinux(),
}
);
But the MachineImage.latestAmazonLinux method does not appear to give an ECS-optimized AMI.
I will need to create two launch templates: one which is ECS-optimized, and another which is ECS-optimized with GPU support.
The AMI's I am currently using are:
Is there any way in CDK to specify that an ECS optimized AMI is required, and that an AMI with GPU support is required?
And if not, how can I specify a specific AMI in CDK when creating a launch template?
You can use the EcsOptimizedImage construct ecs.EcsOptimizedImage.amazonLinux2(ecs.AmiHardwareType.GPU)
let launch_template = new ec2.LaunchTemplate(
this,
'MyLaunchTemplate',
{
instanceType: params.instanceType,
machineImage: ecs.EcsOptimizedImage.amazonLinux2(ecs.AmiHardwareType.GPU)
}
);
Also in order to pick the exact AMI you can give the region ami map
machineImage: ec2.MachineImage.genericLinux({
'us-east-1': 'ami-xxxxxxxxxx',
})