Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

418
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

0

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

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

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda