Skip to content

app.getAllContext() returns empty object #2239

@piurafunk

Description

@piurafunk

I am attempting to parse some context values from the CDK app. The feature was introduced by #1751

My code snippet is:

const app = new cdk.App();
console.log(app.node.getAllContext());

Which outputs:

{}

However, when I toss a console.log() in Node.getAllContext(), it prints my context variables:

console.log(this._context)

Outputs:

...
  '@aws-cdk/aws-ec2:restrictDefaultSecurityGroup': true,
  '@aws-cdk/aws-apigateway:requestValidatorUniqueId': true,
  longTermStorageBucketArn: 'backups-690e',
  'aws:cdk:enable-path-metadata': true,
  'aws:cdk:enable-asset-metadata': true,
...

Where longTermStorageBucketArn is the context I have passed on command line:

npm run cdk -- -c longTermStorageBucketArn=backups-690e synth

I also tested it in the constructor of a Stack object:

console.log('all context', this.node.getAllContext())
// as well as
console.log('all context', scope.node.getAllContext())

both of which produce:

all context {}

Is this the intended behavior? I don't seem to understand how to get all context from the app object, whereas app.node.getContext(...) works as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions