Is there a way to create AWS launch template version with a component removed?

60 views Asked by At

Is it possible to create a LT version without an element that is present in the original LT? For example, let's say we have a LT that includes "BlockDeviceMappings", "IamInstanceProfile", "ImageId", "KeyName", etc., and we need new LT version that has everything from the original LT except "KeyName".

I know we can easily do it using AWS Console, but I need to do it programmatically, preferable via Python / boto3.

I tried using "None" and "" for "KeyName" in LaunchTemplateData argument for create_launch_template_version - getting error in both cases.

1

There are 1 answers

0
Boris Trukhnov On

I found a solution.

 response = ec2.describe_launch_template_versions(LaunchTemplateId='<lt_id>', Versions = ['<source_version>'])
 response['LaunchTemplateVersions'][0]['LaunchTemplateData'].pop('KeyName')
 lt_data = response['LaunchTemplateVersions'][0]['LaunchTemplateData']
 ec2.create_launch_template_version(LaunchTemplateId = '<lt_id>', LaunchTemplateData = lt_data)