Refactor: reduce copy-paste boilerplate in ec2 run-instances _fix_args

Open Beginner friendly
#10,562 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
84/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Quiet
Tech stack
python
Domain
cli

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

needs-triage

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from aws/aws-cli

All issues in aws/aws-cli

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.