Skip to content

ec2 run-instances: --no-associate-public-ip-address silently ignored when mixed with --network-interfaces #10558

Description

@Adityaj0

Describe the bug

aws ec2 run-instances --network-interfaces ... is documented to reject mixing with the "simple, scalar" options (--associate-public-ip-address, --secondary-private-ip-addresses, --secondary-private-ip-address-count) by raising:

Mixing the --network-interfaces option with the simple, scalar options is not supported.

This works correctly for --associate-public-ip-address, but not for its counterpart --no-associate-public-ip-address. That flag is silently accepted instead of raising the same error, and it also overwrites AssociatePublicIpAddress inside the user's own --network-interfaces JSON to False — even if the user's JSON explicitly set it to True.

Expected Behavior

--no-associate-public-ip-address combined with --network-interfaces should raise the same ParamValidationError that --associate-public-ip-address does.

Current Behavior

The command silently succeeds and mutates NetworkInterfaces[0]["AssociatePublicIpAddress"] to False.

Reproduction Steps

aws ec2 run-instances --image-id ami-0123456789 \
  --network-interfaces '[{"DeviceIndex":0,"SubnetId":"subnet-abc","AssociatePublicIpAddress":true}]' \
  --no-associate-public-ip-address

Compare with (correctly errors):

aws ec2 run-instances --image-id ami-0123456789 \
  --network-interfaces '[{"DeviceIndex":0,"SubnetId":"subnet-abc"}]' \
  --associate-public-ip-address

Root cause

In awscli/customizations/ec2/runinstances.py, _check_args() only checks the associate_public_ip_address dest (set by --associate-public-ip-address, action='store_true'). It never checks no_associate_public_ip_address (set by --no-associate-public-ip-address, action='store_false'), which is a distinct argparse dest even though both flags share a group_name for help-text grouping only.

Fix

I've opened a PR with a fix and regression tests: will link below.

Environment

  • aws-cli/2.x (customization present on current v2 branch)

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triageThis issue or PR still needs to be triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions