Refactor: reduce copy-paste boilerplate in ec2 run-instances _fix_args
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 84/100
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.
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.
- Dominant language
- Python
- Stars
- 17.3k
- Forks
- 4.7k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 21
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from aws/aws-cli
-
bug needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
codeartifact login investigating p2
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
needs-triage
Difficulty 1/5 Under an hour Newbie friendliness 90/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100