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

280
Views
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 answers
Answer question

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 Report

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