How do I provide a binary attribute value in an AWSCustomResource DynamoDB PutRequest?

0

Hello. I am attempting to write CDK code to populate a DynamoDB table. The table has several attributes, including a binary attribute:

new AwsCustomResource(this, id, {
        onCreate: {
            service: 'DynamoDB',
            action: 'putItem',
            parameters: {
                TableName: tableName,
                Item: {
                    A1: { S: "hello" },
                    A2: { B: how do I do this?? },
                    A3: { N: "1" }
                }
            },
            physicalResourceId: PhysicalResourceId.of(contentKeysInitName)
        }

I've tried various formats that I've seen on the web, and with all of them I get the error "Received response status [FAILED] from custom resource. Message returned: Cannot read properties of undefined (reading 'byteLength')"

I've also seen references to the usage of Uint8array, but no clear examples of how to use it.

Thanks in advance.

2 Answers
1

DynamoDB accepts all data parameters as string values, and binary values should be base64 encoded strings:

  parameters: {
                TableName: tableName,
                Item: {
                    "A1": { "S": "hello" },
                    "A2": { "B": "aG93IGRvIEkgZG8gdGhpcz8/" },
                    "A3": { "N": "1" }
                }
            }
profile pictureAWS
EXPERT
answered 8 months ago
0

It doesn't work. I get the error I previously posted.

answered 8 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions