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

281
Visualizações
AWS-CDK - DynamoDB Initial Data

Using the AWS CDK for a Serverless project but I've hit a sticking point. My project deploys a DynamoDB table which I need to populate with data prior to my Lambda function executing.

The data that needs to be loaded is generated by making API calls and isn't static data that can be loaded by a .json file or something simple.

Any ideas on how to approach this requirement for a production workload?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You can use AwsCustomResource in order to make a PutItem call to the table.

AwsSdkCall initializeData = AwsSdkCall.builder()
        .service("DynamoDB")
        .action("putItem")
        .physicalResourceId(PhysicalResourceId.of(tableName + "_initialization"))
        .parameters(Map.ofEntries(
                Map.entry("TableName", tableName),
                Map.entry("Item", Map.ofEntries(
                        Map.entry("id", Map.of("S", "0")),
                        Map.entry("data", Map.of("S", data))
                )),
                Map.entry("ConditionExpression", "attribute_not_exists(id)")
        ))
        .build();

AwsCustomResource tableInitializationResource = AwsCustomResource.Builder.create(this, "TableInitializationResource")
        .policy(AwsCustomResourcePolicy.fromStatements(List.of(
                PolicyStatement.Builder.create()
                        .effect(Effect.ALLOW)
                        .actions(List.of("dynamodb:PutItem"))
                        .resources(List.of(table.getTableArn()))
                        .build()
        )))
        .onCreate(initializeData)
        .onUpdate(initializeData)
        .build();
tableInitializationResource.getNode().addDependency(table);

The PutItem operation will be triggered if the stack is created or if table is updated (tableName is supposed to be different in that case). If it doesn't work for some reason, you can set physicalResourceId to random value, i.e. UUID, to trigger the operation for each stack update (the operation is idempotent due to ConditionExpression)

over 4 years ago · Santiago Trujillo Relatório

0

CustomResource allows you to write custom provisioning logic. In this case you could use something like a AWS Lambda Function in a Custom Resource to read in the custom json and update DynamoDb.

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