Refactor: reduce copy-paste boilerplate in ec2 run-instances _fix_args
- Dominant language
- Python
- Stars
- 17.3k
- Forks
- 4.6k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 13
Description
## Summary
\`awscli/customizations/ec2/runinstances.py\`'s \`_fix_args\` (lines ~120-141) moves several scalar top-level params (\`SubnetId\`, \`SecurityGroupIds\`, \`Ipv6AddressCount\`, \`Ipv6Addresses\`, \`EnablePrimaryIpv6\`) into the \`NetworkInterfaces[0]\` structure using six nearly-identical \`if key in params: interface[dest] = params[key]; del params[key]\` blocks.
Only the source/dest key names differ between blocks (aside from the \`PrivateIpAddress\` case, which needs real transformation into a \`PrivateIpAddresses\` list). This is pure copy-paste boilerplate that has grown over time as EC2 added more network-interface-eligible params, and is easy to get wrong (typo in source vs dest vs delete key) when extended further.
## Proposed change
Replace the simple rename-and-move blocks with a declarative mapping (e.g. a \`SIMPLE_PARAM_MAP\` dict of source key -> destination key) and a small loop, keeping the \`PrivateIpAddress\` case as the one special-cased transform. This shortens the function and makes future additions a one-line map entry instead of a new if-block.
No behavior change intended — this is a pure refactor.
Contributor guide
Research direction
Open awscli/customizations/ec2/runinstances.py and inspect _fix_args around lines 120-141. Compare the repeated scalar parameter moves with the separate PrivateIpAddress transformation, then refactor only the simple rename-and-move cases into a mapping and loop. Done means the boilerplate is reduced while parameter behavior remains unchanged, including the PrivateIpAddress special case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Refactor
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 84/100