- Newest
- Most votes
- Most comments
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.
Relevant content
- asked 2 years ago
- asked a year ago
- AWS OFFICIALUpdated 3 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 3 months ago
- AWS OFFICIALUpdated 2 years ago
I'm doing this in terraform, can't seem to find 'source-version' under launch template?