Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/next-release/bugfix-ec2-55884.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "bugfix",
"category": "ec2",
"description": "Fix `aws ec2 run-instances --network-interfaces ... --no-associate-public-ip-address` silently overwriting AssociatePublicIpAddress in the user-supplied network interface instead of raising the documented error for mixing --network-interfaces with scalar options"
}
12 changes: 7 additions & 5 deletions awscli/customizations/ec2/runinstances.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,20 @@ def _check_args(parsed_args, **kwargs):
# raise an error.
arg_dict = vars(parsed_args)
if arg_dict['network_interfaces']:
msg = (
'Mixing the --network-interfaces option '
'with the simple, scalar options is '
'not supported.'
)
for key in (
'secondary_private_ip_addresses',
'secondary_private_ip_address_count',
'associate_public_ip_address',
):
if arg_dict[key]:
msg = (
'Mixing the --network-interfaces option '
'with the simple, scalar options is '
'not supported.'
)
raise ParamValidationError(msg)
if arg_dict['no_associate_public_ip_address'] is False:
raise ParamValidationError(msg)


def _fix_args(params, **kwargs):
Expand Down
18 changes: 18 additions & 0 deletions tests/functional/ec2/test_run_instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,24 @@ def test_private_ip_address_alone(self):
}
self.assert_run_instances_call(args, result)

def test_network_interfaces_with_associate_public_ip_address_errors(self):
args = ' --image-id ami-foobar --count 1 '
args += '--network-interfaces DeviceIndex=0 '
args += '--associate-public-ip-address'
self.run_cmd(self.prefix + args, expected_rc=252)

def test_network_interfaces_with_no_associate_public_ip_address_errors(self):
# Regression test: --no-associate-public-ip-address is a separate
# argparse dest (no_associate_public_ip_address) from
# --associate-public-ip-address (associate_public_ip_address), so
# it must be checked on its own. Previously this silently
# overwrote AssociatePublicIpAddress inside the user-supplied
# --network-interfaces structure instead of raising.
args = ' --image-id ami-foobar --count 1 '
args += '--network-interfaces DeviceIndex=0 '
args += '--no-associate-public-ip-address'
self.run_cmd(self.prefix + args, expected_rc=252)

def test_ipv6_address_count_and_associate_public_ip_address(self):
args = ' --associate-public-ip-address'
args += ' --ipv6-address-count 5 --image-id ami-foobar --count 1'
Expand Down