Allow multiple regions to be specified on invocation
- Dominant language
- Python
- Stars
- 17.3k
- Forks
- 4.6k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 13
Description
### Describe the feature
For selected subcommands (such as `ses list-identities` or `ec2 describe-vpcs`), allow the user to specify multiple regions for execution using the `--region` command line switch. Rather than specifying a single region name, the user would provide a comma separated list of region names. For this enhancement to be relevant, the subcommand would need to
1. Be region specific
2. Allow execution without a specifying an instance identifier
When multiple regions are specified, the output would be generated in map form, with the map keys being the region name where the command was executed and the map values being the output of the command execution.
### Use Case
From time to time, we need to gather information about our AWS environment across all of our accounts and regions. To gather this information, we resort to using a shell looping construct similar to the following
```bash
echo -n "{" > ses.json
for R in us-east-2 us-east-1 us-west-1 us-west-2 af-south-1 ap-south-1 ap-northeast-3 ap-northeast-2 ap-southeast-1 ap-southeast-2 ap-northeast-1 ca-central-1 eu-central-1 eu-west-1 eu-west-2 eu-south-1 eu-west-3 eu-north-1 me-south-1 sa-east-1
do
echo -n "${R}:" | tee -a ses.json
aws --output=json --region=${R} ses list-identities >> ses.json
echo "," >> ses.json
done
echo "}" >> ses.json
```
A problem with the above construct is that it fails to produce syntactically correct json (though the output is close)
The proposed feature would allow us to make the invocation as follows
`aws --output=json --region=us-east-2,us-east-1,us-west-1,us-west-2,af-south-1,ap-south-1,ap-northeast-3,ap-northeast-2,ap-southeast-1,ap-southeast-2,ap-northeast-1,ca-central-1,eu-central-1,eu-west-1,eu-west-2,eu-south-1,eu-west-3,eu-north-1,me-south-1,sa-east-1 ses list-identities > ses.json`
This would have the side benefit of producing syntactically correct json.
### Proposed Solution
A naive (and untested) implementation of the change is as follows
```diff
index 304cebbe6..1baef958e 100644
--- a/awscli/clidriver.py
+++ b/awscli/clidriver.py
@@ -645,12 +645,23 @@ class CLIOperationCaller(object):
value is returned.
"""
- client = self._session.create_client(
- service_name, region_name=parsed_globals.region,
- endpoint_url=parsed_globals.endpoint_url,
- verify=parsed_globals.verify_ssl)
- response = self._make_client_call(
- client, operation_name, parameters, parsed_globals)
+ regions = parsed_globals.region.split(',')
+ response = {}
+ if 1 == regions.count:
+ client = self._session.create_client(
+ service_name, region_name=parsed_globals.region,
+ endpoint_url=parsed_globals.endpoint_url,
+ verify=parsed_globals.verify_ssl)
+ response = self._make_client_call(
+ client, operation_name, parameters, parsed_globals)
+ else:
+ for region in regions:
+ client = self._session.create_client(
+ service_name, region_name=region,
+ endpoint_url=parsed_globals.endpoint_url,
+ verify=parsed_globals.verify_ssl)
+ response[region] = self._make_client_call(
+ client, operation_name, parameters, parsed_globals)
self._display_response(operation_name, response, parsed_globals)
return 0
```
### Other Information
_No response_
### Acknowledgements
- [X] I may be able to implement this feature request
- [ ] This feature might incur a breaking change
### CLI version used
aws-cli/2.7.7 Python/3.9.13 Darwin/21.6.0 source/arm64 prompt/off
### Environment details (OS name and version, etc.)
Darwin ablack0321 21.6.0 Darwin Kernel Version 21.6.0: Sat Jun 18 17:05:47 PDT 2022; root:xnu-8020.140.41~1/RELEASE_ARM64_T8101 arm64
Contributor guide
Assessment
This issue has not been assessed yet.