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

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

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 Denunciar

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 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