Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CDK CLI: region must be in config file (ignored in credentials file) since 2.167.0 #32130

Closed
1 task done
rix0rrr opened this issue Nov 14, 2024 · 8 comments · Fixed by #32133
Closed
1 task done

CDK CLI: region must be in config file (ignored in credentials file) since 2.167.0 #32130

rix0rrr opened this issue Nov 14, 2024 · 8 comments · Fixed by #32133
Labels
bug This issue is a bug. effort/medium Medium work item – several days of effort p0 package/tools Related to AWS CDK Tools or CLI

Comments

@rix0rrr
Copy link
Contributor

rix0rrr commented Nov 14, 2024

Describe the bug

From this thread: #32120

By @otbe:


For us the issue is in the region, e.g.

deploy -vvv

10:38:42] Looking up AWS region in the EC2 Instance Metadata Service (IMDS).
[10:38:43] Unable to retrieve AWS region from IMDS: Error: Error fetching metadata token: TimeoutError: Connection timed out after 1000 ms
[10:38:43] Unable to determine AWS region from environment or AWS configuration (profile: "default"), defaulting to 'us-east-1'

Not quite sure how it worked in older aws-cdk versions but the region is specified in .aws/credentials similar to this

[default]
aws_access_key_id=
aws_secret_access_key=
aws_session_token=
aws_security_token=
region=eu-central-1

That means our stacks are deployed in the wrong region with 2.167.0 🫠
Reverting back to 2.166.0 solves the issue.

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

No response

Expected Behavior

Uses my configured region in the INI file

Current Behavior

Uses us-east-1

Reproduction Steps

See description

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.167.0

Framework Version

No response

Node.js Version

OS

Language

TypeScript

Language Version

No response

Other information

No response

@rix0rrr rix0rrr added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 14, 2024
@github-actions github-actions bot added package/tools Related to AWS CDK Tools or CLI potential-regression Marking this issue as a potential regression to be checked by team member labels Nov 14, 2024
@rix0rrr
Copy link
Contributor Author

rix0rrr commented Nov 14, 2024

If the statement is in the ~/.aws/config file it works, just not when it's in the ~/.aws/credentials file. The SDKv2 treated these files the same, the SDKv3 apparently does not.

Strangely enough the AWS CLI does also seem to support the value in both config files, even though it has been specced to only work in the config file.

Location of [default] region= statement Works in 2.167.0 Works in AWS CLI
~/.aws/credentials
~/.aws/config

Examples say the region should go into config

All examples of these files also always put keys in credentials and other values in config:

https://docs.aws.amazon.com/cli/v1/userguide/cli-configure-files.html

image

Documentation say the region flag is only specced for the config file

https://docs.aws.amazon.com/cli/v1/userguide/cli-configure-files.html

image

aws configure puts region into config

If you run

$ aws configure

And fill in all the values, that command will put the region into the config file, not the credentials file

@otbe
Copy link

otbe commented Nov 14, 2024

Interesting findings. What is also somehow strange we have a lot of node scripts with aws sdkv3 running in the same setup (region in /credentials) and they still work fine.

@rix0rrr
Copy link
Contributor Author

rix0rrr commented Nov 14, 2024

What is also somehow strange we have a lot of node scripts with aws sdkv3 running in the same setup (region in /credentials) and they still work fine.

That is quite weird indeed.

It might be that there's a difference between the code paths that determine a region for the purposes of making an API call, versus the code paths that we use to query the region.

@rix0rrr
Copy link
Contributor Author

rix0rrr commented Nov 14, 2024

Ah yeah, it's us:

return sharedFiles?.configFile?.[profile]?.region || sharedFiles?.configFile?.default?.region;

@rix0rrr rix0rrr changed the title CDK CLI: Unable to determine AWS region from environment or AWS configuration since 2.167.0 CDK CLI: region must be in config file (ignored in credentials file) since 2.167.0 Nov 14, 2024
@otbe
Copy link

otbe commented Nov 14, 2024

Just for confirmation: after putting the region into .aws/config everything works again :)

@ashishdhingra ashishdhingra added p1 and removed needs-triage This issue or PR still needs to be triaged. labels Nov 14, 2024
@ashishdhingra
Copy link
Contributor

Labeling the issue as p1 for now since it is being actively worked upon.

@mrgrain mrgrain removed the potential-regression Marking this issue as a potential regression to be checked by team member label Nov 14, 2024
@ashishdhingra ashishdhingra added the effort/medium Medium work item – several days of effort label Nov 14, 2024
@mergify mergify bot closed this as completed in #32133 Nov 14, 2024
@mergify mergify bot closed this as completed in d1b3c81 Nov 14, 2024
Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

1 similar comment
Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 14, 2024
mrgrain pushed a commit that referenced this issue Nov 14, 2024
We just didn't consider the shared credentials file as returned by the SDK when loading configuration. 

Closes #32130.

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@iliapolo iliapolo added p0 and removed p1 labels Nov 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug. effort/medium Medium work item – several days of effort p0 package/tools Related to AWS CDK Tools or CLI
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants