launch templates and AWS image builder using old user-data

0

I'm using AMI image builder to build the base image for an AMI, when the AMI is released it updates the AMI on a launch template however, if I try to update the User data script which is on the LT, there's a weird issue where the LT user-data gets updated but it doesn't select the new AMI, it just blank which makes the launch template using the old version of the template with the older AMI.

When I run the AMI builder it'll update the Launch template but will use the old version of the user data script.

joet
질문됨 일 년 전340회 조회
1개 답변
0

It seems like the issue might be due to the order of operations during the updating of the Launch Template. When you're updating the Launch Template with the new AMI, make sure you're also specifying the updated user-data script at the same time.

Here's an example of how you might do this using the AWS CLI:

aws ec2 create-launch-template-version --launch-template-id lt-0abcd1234ef56789a --source-version $old_version --launch-template-data file://launch-template-data.json

In this command, lt-0abcd1234ef56789a is the ID of the launch template you're updating and $old_version is the version of the launch template you're using as a base. The launch-template-data.json file should include the ID of the new AMI and the updated user-data script.

The launch-template-data.json file would look something like this:

{
    "ImageId": "ami-0abcd1234ef56789a",
    "UserData": "IyEvYmluL2Jhc2gKCnN1ZG8gYXB0LWdldCB1cGRhdGUgLXkKc3VkbyBhcHQtZ2V0IHVwZ3JhZGUgLXkKc3VkbyBhcHQtZ2V0IGluc3RhbGwgLXkgZ2l0"
}

In this file, ami-0abcd1234ef56789a is the ID of the new AMI and IyEvYmluL2Jhc2gKCnN1ZG8gYXB0LWdldCB1cGRhdGUgLXkKc3VkbyBhcHQtZ2V0IHVwZ3JhZGUgLXkKc3VkbyBhcHQtZ2V0IGluc3RhbGwgLXkgZ2l0 is the Base64-encoded user-data script.

Remember to replace the above details with your own AMI ID, Launch Template ID and UserData script. The UserData script should be Base64 encoded.

It's also important to note that when you create a new version of a launch template, the default version of the launch template doesn't automatically update to the new version. You can set the new version as the default using the modify-launch-template command:

aws ec2 modify-launch-template --launch-template-id lt-0abcd1234ef56789a --default-version $new_version

In this command, lt-0abcd1234ef56789a is the ID of the launch template and $new_version is the version number of the new version you just created.

profile picture
전문가
답변함 일 년 전
  • I'm doing this in terraform, can't seem to find 'source-version' under launch template?

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인