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 Antworten
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
EXPERTE
beantwortet vor 8 Monaten
0

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

beantwortet vor 8 Monaten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen