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.

已提问 8 个月前326 查看次数
2 回答
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
专家
已回答 8 个月前
0

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

已回答 8 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则