aws-cloudformation / aws-cloudformation-resource-providers-awsutilities-commandrunner

Apache License 2.0
81 stars 21 forks source link

Better region determination in register.sh #53

Closed gitshawn closed 6 months ago

gitshawn commented 1 year ago

Description of changes:

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

shantgup commented 6 months ago

Thank you for the pull request, we appreciate your contribution.

The current way with aws configure get region installs to the current region being used by the CLI. aws ec2 describe-availability-zones --output text --query 'AvailabilityZones[0].[RegionName]' would make it always be us-east-1.

gitshawn commented 6 months ago

Respectfully @shantgup that is incorrect.

  1. aws configure... will only parse info from the AWS config in your local dotfiles. If you set AWS_DEFAULT_REGION env var this will not work for example.
  2. aws ec2 describe-availability-zones --output text --query 'AvailabilityZones[0].[RegionName]' does not always return us-east-1 ... it works as expected and described in the PR, worked in the register.sh in my branch, regardless of how you set the region.

See an attached example from CloudShell. There is no dotfiles profile set, and thus aws configure... returns nothing, but the command I shared does, and as CloudShell was executed in Paris region it returns eu-west-3.

image

shantgup commented 6 months ago

I see now, thank you for clarifying @gitshawn. You are correct, I just tried it, and aws ec2 describe-availability-zones --output text --query 'AvailabilityZones[0].[RegionName]' returns the current region - TIL! I thought it was returning a list where 0 would be the first one, but it actually does return the current region. I'll update it to that now. Thank you again 😄