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 · 4 comments
Assignees
Labels
bug This issue is a confirmed bug. ec2 p2 This is a standard priority issue response-requested Waiting on additional information or feedback.

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
@RyanFitzSimmonsAK RyanFitzSimmonsAK self-assigned this Feb 10, 2025
@RyanFitzSimmonsAK RyanFitzSimmonsAK added investigating This issue is being investigated and/or work is in progress to resolve the issue. ec2 p2 This is a standard priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Feb 10, 2025
@RyanFitzSimmonsAK
Copy link
Contributor

Hi @redood, thanks for reaching out. I was able to reproduce this behavior, and did some testing. In your AWS CLI command, your only parameters are --launch-template-id and --launch-template-data. In the Boto3 code, you also added SourceVersion. If I add SourceVersion to the CLI command, BlockDeviceMappings is included in the resulting version. If I omit SourceVersion from the Boto3 code, the version is successfully created without a BlockDeviceMappings.

Hope that helps, please let me know if you have any follow-up questions.

@RyanFitzSimmonsAK RyanFitzSimmonsAK added response-requested Waiting on additional information or feedback. and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Feb 11, 2025
@redood redood closed this as completed Feb 12, 2025
Copy link

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

@redood redood reopened this Feb 12, 2025
@redood
Copy link
Author

redood commented Feb 12, 2025

Ignore me accidentally closing this.

@RyanFitzSimmonsAK Thanks for your suggestion -- I'll try it out in our automation.
We've always used SourceVersion before in our LT operations so never tried it without it.

Am I correct to assume that SourceVersion wouldn't matter under any circumstance if the entire LaunchTemplateData is provided?

Also if this does resolve my issue, should I close this ticket or leave it open (i.e. do you see the current behavior as something that needs fixing?)

Thx

@RyanFitzSimmonsAK
Copy link
Contributor

I think this could be closed if it resolves your issue. Looking at the documentation for CreateLaunchTemplateVersion, this is appears to be intended.

The version of the launch template on which to base the new version. Snapshots applied to the block device mapping are ignored when creating a new version unless they are explicitly included.

If you specify this parameter, the new version inherits the launch parameters from the source version. If you specify additional launch parameters for the new version, they overwrite any corresponding launch parameters inherited from the source version.

If you omit this parameter, the new version contains only the launch parameters that you specify for the new version.

Based on this, SourceVersion wouldn't matter if the entire LaunchTemplateData is provided, since they'd all be overwritten.

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. ec2 p2 This is a standard priority issue response-requested Waiting on additional information or feedback.
Projects
None yet
Development

No branches or pull requests

2 participants