-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Cannot retrieve value from context provider vpc-provider since account/region are not specified at the stack level #3130
Comments
This is the expected behavior >= 0.36.0. We wanted to reduce the implicit effect the user's environment has on the synthesis result as this can cause production risks, so we made this explicit. If you don't specify DeploymentStack(
app=app,
id='Dev',
env={
'account': os.environ['CDK_DEFAULT_ACCOUNT'],
'region': os.environ['CDK_DEFAULT_REGION']
}
) |
In this case I had both account and region specified in env as outlined here: https://gist.github.com/mrcustard/828242e3e5b8786776fd0c78d1e74e63#file-mssymbol-server-cdk-ts-L17-L18 and I still received the error message |
I'm using
|
Workaround is to set up env in the stack. Wonder how to autofill this with my account number from my profile next. |
@kaihendry you do not have to set these variables. They are set by CDK but you have to use them in den StackProps. {
env: {
account: process.env.CDK_DEFAULT_ACCOUNT,
region: process.env.CDK_DEFAULT_REGION,
},
} |
@hoegertn @eladb I'm doing exactly as you advise and I'm still getting this error when attempting to lookup an existing VPC. Very frustrating to get started with CDK due to this issue. `import cdk = require("@aws-cdk/core"); export class TestInitStack extends cdk.Stack {
} new TestInitStack(new cdk.App(), "TestInitStack", { cdk --verbose ls |
In case someone runs into this problem and made the same mistake as me. (@niels1voo it looks like you might have). I had been constructing my own stack and properly passing in the env. But I used the boilerplate and it had its own stack in |
You can also use account_name instead of aws account number : new InfrastructureStack(app, 'sample-app-stack', { export CDK_DEFAULT_ACCOUNT=awsAccountName |
That's correct and just adding to that, the code would be something like const process = require('process');
const app = new cdk.App();
new CdkTypescriptDemoStack(app, 'CdkTypescriptDemoStack', {
env: {
account: process.env.CDK_DEFAULT_ACCOUNT,
region: process.env.CDK_DEFAULT_REGION
},
}); |
Even when provided, it still reports error:
|
A possible solution, if you end up here My pipeline stack was not passing the props to its parent
working: export class PipelineStack extends Stack {
private props: PipelineStackProps;
private artifacts: Map<string, Artifact>;
private buildActions: Map<string, CodeBuildAction>;
private resourcePrefix: string;
constructor(scope: Construct, id: string, props: PipelineStackProps) {
super(scope, id, props); |
Note: for support questions, please first reference our documentation, then use Stackoverflow. This repository's issues are intended for feature requests and bug reports.
I'm submitting a ...
What is the current behavior?
When trying to use ec2.Vpc.fromLookup, and passing { env: { region: "your-region", account: "your-account-id"} } I get and error when doing
cdk list
: Cannot retrieve value from context provider vpc-provider since account/region are not specified at the stack levelLink to code: https://gist.github.com/mrcustard/828242e3e5b8786776fd0c78d1e74e63
What is the expected behavior (or behavior of feature suggested)?
I would expect to be able to lookup the vpc and get ec2.IVPc returned
Please tell us about your environment:
Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. associated pull-request, stackoverflow, gitter, etc)
The text was updated successfully, but these errors were encountered: