Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

415
Views
How do I pass in values to AWS CDK at deploy time?

How do I pass in values to AWS CDK at deploy time (not synth time)?

I can see that I can retrieve context values within an App:

(String)app.getNode().tryGetContext("keyOfMyValue");

The example above is from the Java API and returns a string where the key value pair was passed using -c keyOfMyValue=someValue. This value is then passed to cdk synth.

Whilst the CLI help for cdk deploy shows an identical Context parameter, I don't see how to access that within a Stack. I specifically don't want to have all values defined at the time of synthesis, I want to pass some simple values (e.g. strings) to CDK at deploy time.

Is there an example of how to do this?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

This snippet will be in .NET but I assume that you can do something similar in Java. Assuming your stack is named astack ...

You can gather the context value with

cdk deploy astack -c environment=prod
var app = new App();
var environment = app.Node.TryGetContext("environment")?.ToString() ?? "dev";

make a class and interface...

public interface IAStackProps : IStackProps
{
    public string Environment { get; set; }
}

public class AStackProps : StackProps, IAStackProps
{
    public string Environment { get; set; }
}

pass it with...

new AStack(app, stackName, new AStackProps {
    Environment = environment,
    ...
});

then you can access it in your stack.

public AStack(Construct scope, string id, IAStackProps props = null) : 
    base(scope, id, props)
{
    // props.Environment
over 4 years ago · Santiago Trujillo Report

0

Stack is a child of Construct (as App), so - the same way, I guess:

this.getNode().tryGetContext()
over 4 years ago · Santiago Trujillo Report

0

Passing deploy-time parameters is done with the combination of a) creating CloudFormation template parameters using CfnParameter class, and then b) passing their values with "--parameters" argument of the cdk deploy command. Details at https://docs.aws.amazon.com/cdk/latest/guide/parameters.html.

It's worth nothing that "--context" parameters - the synth-time parameters, may still be passed with cdk deploy, because "cdk deploy" runs "cdk synth" implicitly.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!