iann0036 / AWSConsoleRecorder

Records actions made in the AWS Management Console and outputs the equivalent CLI/SDK commands and CloudFormation/Terraform templates.
MIT License
1.42k stars 87 forks source link

ec2.runInstances BlockDeviceMapping "NoDevice" #19

Closed jbananas closed 5 years ago

jbananas commented 5 years ago

Describe the bug aws ec2 run-instances is generating "NoDevice" block device mappings for every letter of the alphabet. The generated commands are technically correct, so this may be a feature request to suppress "NoDevice" mappings, rather than a bug :)

Related Mapping ec2.runInstances

Related Language CLI and Python tested.

To Reproduce Steps to reproduce the behavior:

  1. Start recorder
  2. Run through EC2 Launch Instances wizard, accept all defaults.
  3. Stop recorder.

Expected behavior Expect Block Device Mappings for existent devices only. Instead we get:

aws ec2 run-instances --image-id "ami-0f4c7e570f044b46f" --count 1 --key-name "xxxxxx" --instance-type "t2.micro" --placement "{\"Tenancy\":\"default\"}" --monitoring "{\"Enabled\":false}" --enable-api-termination --instance-initiated-shutdown-behavior "stop" --credit-specification "{\"CpuCredits\":\"standard\"}" --no-ebs-optimized --block-device-mappings "[{\"DeviceName\":\"/dev/sda1\",\"Ebs\":{\"VolumeSize\":30,\"DeleteOnTermination\":true,\"VolumeType\":\"gp2\"}},{\"DeviceName\":\"xvdca\",\"NoDevice\":\"\"},{\"DeviceName\":\"xvdcb\",\"NoDevice\":\"\"},{\"DeviceName\":\"xvdcc\",\"NoDevice\":\"\"},{\"DeviceName\":\"xvdcd\",\"NoDevice\":\"\"},{\"DeviceName\":\"xvdce\",\"NoDevice\":\"\"},{\"DeviceName\":\"xvdcf\",\"NoDevice\":\"\"},{\"DeviceName\":\"xvdcg\",\"NoDevice\":\"\"},{\"DeviceName\":\"xvdch\",\"NoDevice\":\"\"},{\"DeviceName\":\"xvdci\",\"NoDevice\":\"\"},{\"DeviceName\":\"xvdcj\",\"NoDevice\":\"\"},{\"DeviceName\":\"xvdck\",\"NoDevice\":\"\"},{\"DeviceName\":\"xvdcl\",\"NoDevice\":\"\"},{\"DeviceName\":\"xvdcm\",\"NoDevice\":\"\"},{\"DeviceName\":\"xvdcn\",\"NoDevice\":\"\"},{\"DeviceName\":\"xvdco\",\"NoDevice\":\"\"},{\"DeviceName\":\"xvdcp\",\"NoDevice\":\"\"},{\"DeviceName\":\"xvdcq\",\"NoDevice\":\"\"},{\"DeviceName\":\"xvdcr\",\"NoDevice\":\"\"},{\"DeviceName\":\"xvdcs\",\"NoDevice\":\"\"},{\"DeviceName\":\"xvdct\",\"NoDevice\":\"\"},{\"DeviceName\":\"xvdcu\",\"NoDevice\":\"\"},{\"DeviceName\":\"xvdcv\",\"NoDevice\":\"\"},{\"DeviceName\":\"xvdcw\",\"NoDevice\":\"\"},{\"DeviceName\":\"xvdcx\",\"NoDevice\":\"\"},{\"DeviceName\":\"xvdcy\",\"NoDevice\":\"\"},{\"DeviceName\":\"xvdcz\",\"NoDevice\":\"\"}]" --network-interfaces "[{\"DeviceIndex\":0,\"Description\":\"Primary network interface\",\"DeleteOnTermination\":true,\"SubnetId\":\"subnet-xxxxxx\",\"Groups\":[\"sg-xxxxxxxx\"],\"Ipv6AddressCount\":0}]" --region us-east-1

or

response = ec2_client.run_instances(
    ImageId='ami-0f4c7e570f044b46f',
    MaxCount=1,
    MinCount=1,
    KeyName='xxxxxx',
    InstanceType='t2.micro',
    Placement={
        'Tenancy': 'default'
    },
    Monitoring={
        'Enabled': False
    },
    DisableApiTermination=False,
    InstanceInitiatedShutdownBehavior='stop',
    CreditSpecification={
        'CpuCredits': 'standard'
    },
    EbsOptimized=False,
    BlockDeviceMappings=[
        {
            'DeviceName': '/dev/sda1',
            'Ebs': {
                'VolumeSize': 30,
                'DeleteOnTermination': True,
                'VolumeType': 'gp2'
            }
        },
        {
            'DeviceName': 'xvdca',
            'NoDevice': ''
        },
        {
            'DeviceName': 'xvdcb',
            'NoDevice': ''
        },
        {
            'DeviceName': 'xvdcc',
            'NoDevice': ''
        },
        {
            'DeviceName': 'xvdcd',
            'NoDevice': ''
        },
        {
            'DeviceName': 'xvdce',
            'NoDevice': ''
        },
        {
            'DeviceName': 'xvdcf',
            'NoDevice': ''
        },
        {
            'DeviceName': 'xvdcg',
            'NoDevice': ''
        },
        {
            'DeviceName': 'xvdch',
            'NoDevice': ''
        },
        {
            'DeviceName': 'xvdci',
            'NoDevice': ''
        },
        {
            'DeviceName': 'xvdcj',
            'NoDevice': ''
        },
        {
            'DeviceName': 'xvdck',
            'NoDevice': ''
        },
        {
            'DeviceName': 'xvdcl',
            'NoDevice': ''
        },
        {
            'DeviceName': 'xvdcm',
            'NoDevice': ''
        },
        {
            'DeviceName': 'xvdcn',
            'NoDevice': ''
        },
        {
            'DeviceName': 'xvdco',
            'NoDevice': ''
        },
        {
            'DeviceName': 'xvdcp',
            'NoDevice': ''
        },
        {
            'DeviceName': 'xvdcq',
            'NoDevice': ''
        },
        {
            'DeviceName': 'xvdcr',
            'NoDevice': ''
        },
        {
            'DeviceName': 'xvdcs',
            'NoDevice': ''
        },
        {
            'DeviceName': 'xvdct',
            'NoDevice': ''
        },
        {
            'DeviceName': 'xvdcu',
            'NoDevice': ''
        },
        {
            'DeviceName': 'xvdcv',
            'NoDevice': ''
        },
        {
            'DeviceName': 'xvdcw',
            'NoDevice': ''
        },
        {
            'DeviceName': 'xvdcx',
            'NoDevice': ''
        },
        {
            'DeviceName': 'xvdcy',
            'NoDevice': ''
        },
        {
            'DeviceName': 'xvdcz',
            'NoDevice': ''
        }
    ],
    CapacityReservationSpecification={
        'CapacityReservationPreference': 'open'
    },
    NetworkInterfaces=[
        {
            'DeviceIndex': 0,
            'Description': 'Primary network interface',
            'DeleteOnTermination': True,
            'SubnetId': 'subnet-xxxxxxx',
            'Groups': [
                'sg-xxxxxxx'
            ],
            'Ipv6AddressCount': 0
        }
    ]
)
iann0036 commented 5 years ago

Weird one, nice catch!

Seems like this was only happening on Windows-based AMIs and is indeed what the console is sending back to the APIs 🤦‍♂️

I've made it clean up the response in 0.3.6, rolling out now. Do let me know if you continue to see that behaviour.

jbananas commented 5 years ago

Tested and confirmed this appears to be resolved. Thanks!