Vpc.fromLookup can't determine region
See original GitHub issueI receive this 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)
even though I set the env
in the stack and also set the environment variable CDK_DEFAULT_REGION.
Reproduction Steps
import cdk = require('@aws-cdk/core');
import { Vpc } from "@aws-cdk/aws-ec2";
const stack = new cdk.Stack(
new cdk.App(),
'test',
{
env: {
region: 'us-west-2'
}
}
);
Vpc.fromLookup( stack, 'vpc-lookup', { isDefault: true} );
Error Log
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)
Environment
- CLI Version : 1.13.1 (build 96cfc63)
- Framework Version:: 1.13.1
- OS : Linux (Manjaro)
- Language : TypeScript
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:19 (9 by maintainers)
Top Results From Across the Web
Cannot retrieve value from context provider ami since account ...
If we pick apart the error, it's saying in order to locate the proper AMIs for your EC2 instances, it needs a region/account...
Read more >interface VpcLookupOptions · AWS CDK
Whether to match the default VPC. region? Type: string (optional, default: Current stack's environment region). Optional to override inferred region.
Read more >awslabs/aws-cdk - Gitter
JSIIError: Cannot retrieve value from context provider vpc-provider since account/region are not specified at the stack level. Either configure "env" with ...
Read more >[CDK] Vpc.fromLookup()でエラー 「Cannot retrieve value ...
fromLookup ()でエラー 「Cannot retrieve value from context provider vpc-provider since account/region are not specified at the stack level」が ...
Read more >@aws-cdk/aws-ec2 - npm
fromLookup () . The CDK CLI will search for the specified VPC in the the stack's region and account, and import the subnet...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Read up on this: https://docs.aws.amazon.com/cdk/latest/guide/environments.html
If you want to use dynamic AWS accounts, you must use code like the following:
We recommend that you don’t, and that if you want to deploy to 5 different accounts, you instantiate your stack 5 times in your application, once for each account. Defining where a stack goes is different from obtaining credentials necessary to deploy it.
Closing this issue.
@niels1voo, I cannot reproduce your problem. The code you showed works for me as intended. Please open a new issue if you would like to dig into this deeper.
How does it work as a param? I can’t synth a stack which uses
CfnParameter
to pass VpcId tofromLookup
because of the errorVpc.fromLookup() must be concrete (no Tokens)
. I’m struggling to come up with a strategy to synth a stack in CDK which dynamically looks up a vpc based on vpcId or tag input and doesn’t have hardcoded account/region.