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 Synth gives error if credentials are incomplete (1.21.1) #5852

Closed
RenkeMeuwese opened this issue Jan 17, 2020 · 9 comments
Closed

CDK Synth gives error if credentials are incomplete (1.21.1) #5852

RenkeMeuwese opened this issue Jan 17, 2020 · 9 comments
Assignees
Labels
needs-reproduction This issue needs reproduction. package/tools Related to AWS CDK Tools or CLI response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@RenkeMeuwese
Copy link

RenkeMeuwese commented Jan 17, 2020

This is a reposting of #5791, which was linked to PR #5803 but persists from 1.20.0 to 1.21.1.

Reproduction Steps

Using an account not linked to credentials from the default configuration gives errors in the execution of cdk synth.

Error Log

context: {
  'availability-zones:account=2:region=us-east-2': {
    '$providerError': 'Need to perform AWS calls for account 2, but no credentials found. Tried: default credentials.',
    '$dontSaveContext': true
  },
  'aws:cdk:enable-path-metadata': true,
  'aws:cdk:enable-asset-metadata': true
}
outdir: cdk.out
env: {
  CDK_DEFAULT_REGION: 'eu-central-1',
  CDK_DEFAULT_ACCOUNT: '[redacted-main account]',
  CDK_CONTEXT_JSON: '{"availability-zones:account=2:region=us-east-2":{"$providerError":"Need to perform AWS calls for account 2, but no credentials found. Tried: default credentials.","$dontSaveContext":true},"aws:cdk:enable-path-metadata":true,"aws:cdk:enable-asset-metadata":true}',
  CDK_OUTDIR: 'cdk.out',
  CDK_CLI_ASM_VERSION: '1.16.0',
  CDK_CLI_VERSION: '1.21.1'
}
Not making progress trying to resolve environmental context. Giving up.
[Error at /upg/skeleton] Need to perform AWS calls for account 2, but no credentials found. Tried: default credentials.

Environment

  • **CLI Version :1.21.1
  • **Framework Version:1.21.1
  • **OS :Mac OS Catalina
  • **Language :Python

Other

Attached: output file with -v, and output with authentication, which is what we do not want to do at the stage that cdk synth is called. And the code that causes the error, zipped.

Archive.zip

output-v.pdf
outputdummyvsauthenticated.pdf


This is 🐛 Bug Report

@RenkeMeuwese RenkeMeuwese added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 17, 2020
@RenkeMeuwese RenkeMeuwese changed the title CDK Synth gives error if credentials are incomplete CDK Synth gives error if credentials are incomplete (1.21.1) Jan 17, 2020
@SomayaB SomayaB added the package/tools Related to AWS CDK Tools or CLI label Jan 17, 2020
@rix0rrr
Copy link
Contributor

rix0rrr commented Jan 20, 2020

This is suspicious to me:

Reading AZs for 2:us-east-2
Setting "availability-zones:account=2:region=us-east-2" context to
{"$providerError":"Need to perform AWS calls for account 2, but no credentials
found. Tried: default credentials.","$dontSaveContext":true}

Where is that account number 2 coming from?

@rix0rrr
Copy link
Contributor

rix0rrr commented Jan 20, 2020

(That should have said [redacted-main-account])

@rix0rrr
Copy link
Contributor

rix0rrr commented Jan 20, 2020

Can you cat cdk.out/manifest.json for me?

@rix0rrr
Copy link
Contributor

rix0rrr commented Jan 20, 2020

Seems to be coming from here:

        self.env = core.Environment(
            account=os.getenv('AWS_ACCOUNT'),
            region=os.getenv('AWS_REGION')
        )

@rix0rrr
Copy link
Contributor

rix0rrr commented Jan 20, 2020

I'm going to guess while running the app your environment looked like this:

AWS_ACCESS_KEY_ID=...
AWS_SECRET_ACCESS_KEY=...
AWS_SESSION_TOKEN=...
AWS_ACCOUNT=2
AWS_REGION=us-east-2

You're probably intending to use os.getenv('CDK_DEFAULT_ACCOUNT') which translates to "the account you currently have credentials for"

@shivlaks shivlaks added needs-reproduction This issue needs reproduction. and removed needs-triage This issue or PR still needs to be triaged. labels Jan 21, 2020
@shivlaks
Copy link
Contributor

@RenkeMeuwese - could you please follow up with the suggestions that @rix0rrr has outlined? I also suspect that this is because of your environment set-up. starting with cdk.out and taking a look at the manifest is a great starting point.

@shivlaks shivlaks added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed bug This issue is a bug. labels Jan 21, 2020
@RenkeMeuwese
Copy link
Author

@rix0rrr : you're right, the cli tries to match the os environment with the account '2', which is a dummy account used in the creation of this test project. There is a local file, env.aws.development which is loaded which has this account in it. And indeed this fails.

However, in 1.19.0 this doesn't cause any failure, as cdk synth just doesn't look for full credentials. Using the cdk to create infrastructure as code in a predictable way, we want to continue to be able to produce cloudformation templates without having to provide full credentials every step of the way.

@RenkeMeuwese
Copy link
Author

manifestcat.pdf

@RenkeMeuwese
Copy link
Author

So after some team discussion we discovered that this behavior change comes from #5594. We were creating a NestedStack which looks for availability zones and needs the names of those zones. In 1.19.0 this value was not needed for cdk synth. Documentation on the functionality of cdk.context.json is desireable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-reproduction This issue needs reproduction. package/tools Related to AWS CDK Tools or CLI response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

4 participants