Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

424
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

0

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

this.getNode().tryGetContext()
over 4 years ago · Santiago Trujillo Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda