aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

CDK Error when calling vpc.lookup "Cannot retrieve value from context provider vpc-provider since account/region are not specified at the stack level"

Open philhorrocks opened this issue 6 years ago • 1 comments

:question: General Issue

I have set the props env values for the stack but still get the error. **Cannot retrieve value from context provider vpc-provider since account/region are not specified at the stack level. I have set the env properties and these appear to be set (confirmed by CDK doctor.

ℹ️ CDK environment variables:

  • CDK_DEFAULT_ACCOUNT = 11111111111
  • CDK_DEFAULT_REGION = eu-west-2

also setting the env props in the stack call:

env: { account: '1111111111', region: 'eu-west-2' },

The Question

CDK doctor shows that my default CDK variables are set and also have the .env properties set to pass to the stack props. However, I still seem to be getting the error

Cannot retrieve value from context provider vpc-provider since account/region are not specified at the stack level. Either configure "env" with explicit account and region when you define your stack, or use the environment variables "CDK_DEFAULT_ACCOUNT" and "CDK_DEFAULT_REGION" to inherit environment information from the CLI (not recommended for production stacks) Subprocess exited with error 1

props call:

const InfraDataRefresh_UAT = new InfraDataRefreshStack(app, 'InfraDataRefreshStackDemo',

//parameters

{ env: { account: '1111111111', region: 'eu-west-2' }, accountA: "development-account", accountB: "uat-account", database1: "database-refresh"

});

Environment

  • CDK CLI Version: 1.36
  • Module Version: 1.36
  • OS: OSX
  • **Language: TypeScript

Other information

CDK doctor shows that the environment values are set as expected

ℹ️ CDK Version: 1.36.0 (build 47c9919) ℹ️ AWS environment variables:

  • AWS_SESSION_TOKEN =
  • AWS_DEFAULT_REGION = eu-west-2
  • AWS_SECRET_ACCESS_KEY =
  • AWS_DEFAULT_PROFILE = development-dev
  • AWS_ACCESS_KEY_ID =
  • AWS_SECURITY_TOKEN =
  • AWS_SDK_LOAD_CONFIG = 1 ℹ️ CDK environment variables:
  • CDK_DEFAULT_ACCOUNT =
  • CDK_DEFAULT_REGION = eu-west-2

Profile <source_profile>:

I also a wrapper script to call the STS token service, followed by cdk command. This sets my AWS credentials and account. This seems to work fine and I can use this to select the environment/AWS profile I require. The AWS config file uses a source_profile and then assumes the role of the account. These profiles are then linked to a root MFA account. Running a cdk diff --profile alone with out the script does not work, as there are no credentials for that profile, they are all linked to the source_profile =

philhorrocks avatar Apr 30 '20 07:04 philhorrocks

This can be closed. Its now working and looks like it was the script I was using to create the STS tokens.

philhorrocks avatar Apr 30 '20 12:04 philhorrocks