Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create_launch_template_version persists existing BlockDeviceMappings even when it's not specified #4429

Open
1 task
redood opened this issue Feb 8, 2025 · 0 comments
Labels
bug This issue is a confirmed bug. needs-triage This issue or PR still needs to be triaged.

Comments

@redood
Copy link

redood commented Feb 8, 2025

Describe the bug

We have a bunch of Launch Templates that include a variety of Block Device Mappings.
Some of these LTs only have a single mapping that looks something like

                "BlockDeviceMappings": [
                    {
                        "DeviceName": "/dev/sda1",
                        "Ebs": {
                            "VolumeSize": 10,
                            "VolumeType": ""
                        }
                    }
                ],

For these LTs, we want to create new versions that are the same as existing one except they need to drop this mapping, i.e. have a new version of the LT without any mappings.

We've tried various ways to achieve this, and believe (and confirmed with AWS Support) that the right way would be to basically just drop the entire BlockDeviceMappings -- that is, take the existing LaunchTemplateData from the Source LT Version, remove BlockDeviceMappings, from it, and then pass it to create_launch_template_version as the new LaunchTemplateData.

We confirmed this sequence of steps works as expected with the AWS CLI, but consistently fails with Boto3 for some reason.
With Boto3, the new resulting LT version still has the same mapping as the original version.

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

Expectation is that new LT version will be same as the Source one, but without any BlockDeviceMappings.

Current Behavior

The current behavior (with Boto3) is that the BlockDeviceMappings section shows up in the new LT version despite it being dropped from LaunchTemplateData when calling create_launch_template_version

Reproduction Steps

import boto3

LT = "lt-018d11ccb4e9ef84c"
# base version that has /dev/sda1
BASE_VERSION = "45"

c = boto3.client("ec2")

current_lt = c.describe_launch_template_versions(
    LaunchTemplateId=LT, Versions=[BASE_VERSION]
)["LaunchTemplateVersions"][0]

assert "BlockDeviceMappings" in current_lt["LaunchTemplateData"]
print(current_lt["LaunchTemplateData"]["BlockDeviceMappings"])
# -> [{'DeviceName': '/dev/sda1', 'Ebs': {'VolumeSize': 10, 'VolumeType': ''}}]
# ^ shows that the base version has /dev/sda1 with 10GB EBS

# Now delete the entire BlockDeviceMappings section
del current_lt["LaunchTemplateData"]["BlockDeviceMappings"]
# Confirm it's not there:
assert "BlockDeviceMappings" not in current_lt["LaunchTemplateData"]

# Create new LT version based on one without BlockDeviceMappings
new_lt = c.create_launch_template_version(
    LaunchTemplateId=LT,
    SourceVersion=BASE_VERSION,
    VersionDescription="itenne-manual",
    LaunchTemplateData=current_lt["LaunchTemplateData"],
)


print(new_lt["LaunchTemplateVersion"]["VersionNumber"])
print(new_lt["LaunchTemplateVersion"]["LaunchTemplateData"]["BlockDeviceMappings"])
# -> [{'DeviceName': '/dev/sda1', 'Ebs': {'VolumeSize': 10, 'VolumeType': ''}}]
# ^ IT'S STILL IN THE NEW VERSION !

Attaching output of this script with Boto debug logging enabled
boto3_debug_output.txt

Possible Solution

No response

Additional Information/Context

As noted above, if I do the same thing but with AWS CLI, it works as expected.
Essentially something like this:

aws ec2 create-launch-template-version --launch-template-id lt-018d11ccb4e9ef84c \
--launch-template-data "$(aws ec2 describe-launch-template-versions --versions 45 --launch-template-id lt-018d11ccb4e9ef84c \ 
--query "LaunchTemplateVersions[0].LaunchTemplateData" | jq 'del(.BlockDeviceMappings)')"

SDK version used

1.35.78

Environment details (OS name and version, etc.)

macOS Ventura 13.7.1 [Apple M2 Ultra]

@redood redood added bug This issue is a confirmed bug. needs-triage This issue or PR still needs to be triaged. labels Feb 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a confirmed bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

1 participant