DEV Community

Abhishek Gupta for AWS

Posted on • Originally published at community.aws

3 1

[20 Days of DynamoDB] Day 17 - BatchGetItem operation

Posted: 5/Feb/2024

You can club multiple (up to 100) GetItem requests in a single BatchGetItem operation - this can be done across multiple tables.

Here is an example that fetches includes four GetItem calls across two different tables:

    resp, err := client.BatchGetItem(context.Background(), &dynamodb.BatchGetItemInput{
        RequestItems: map[string]types.KeysAndAttributes{
            "customer": types.KeysAndAttributes{
                Keys: []map[string]types.AttributeValue{
                    {
                        "email": &types.AttributeValueMemberS{Value: "c1@foo.com"},
                    },
                    {
                        "email": &types.AttributeValueMemberS{Value: "c2@foo.com"},
                    },
                },
            },
            "Thread": types.KeysAndAttributes{
                Keys: []map[string]types.AttributeValue{
                    {
                        "ForumName": &types.AttributeValueMemberS{Value: "Amazon DynamoDB"},
                        "Subject":   &types.AttributeValueMemberS{Value: "DynamoDB Thread 1"},
                    },
                    {
                        "ForumName": &types.AttributeValueMemberS{Value: "Amazon S3"},
                        "Subject":   &types.AttributeValueMemberS{Value: "S3 Thread 1"},
                    },
                },
                ProjectionExpression: aws.String("Message"),
            },
        },
        ReturnConsumedCapacity: types.ReturnConsumedCapacityTotal,
    })
Enter fullscreen mode Exit fullscreen mode

Just like an individual GetItem call, you can include Projection Expressions and return RCUs. Note that BatchGetItem can only retrieve up to 16 MB of data.

Recommended reading: BatchGetItem API doc

Billboard image

Imagine monitoring that's actually built for developers

Join Vercel, CrowdStrike, and thousands of other teams that trust Checkly to streamline monitor creation and configuration with Monitoring as Code.

Start Monitoring

Top comments (0)

Billboard image

Try REST API Generation for Snowflake

DevOps for Private APIs. Automate the building, securing, and documenting of internal/private REST APIs with built-in enterprise security on bare-metal, VMs, or containers.

  • Auto-generated live APIs mapped from Snowflake database schema
  • Interactive Swagger API documentation
  • Scripting engine to customize your API
  • Built-in role-based access control

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay