0
votes

I am trying to use the DynamoDB transactWrite function from node sdk (https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html#transactWrite-property)

For my lambda functions that are invoked by API Gateway triggers the function works as expected, but for my lambda functions invoked by DynamoDB Stream events I get the following error.

TypeError: n.transactWrite is not a function\n

All Lambda functions are on 10.X runtime.

Below is an example of how I am invoking the function with dummy data for illustrative purposes.


import { DynamoDB } from 'aws-sdk'

const dynamoDb: DynamoDB.DocumentClient = new DynamoDB.DocumentClient({})

const request: DynamoDB.DocumentClient.TransactWriteItemsInput = {
  TransactItems: [{
    Update: {
      TableName: "example",
      Key: {
        partitionKey: "someid",
        sortKey: "somesortkey",
      },
      UpdateExpression: 'set gsi1sk = :gsi1sk',
      ExpressionAttributeValues: {
        ':gsi1sk': "somenewvalue"
      },
          },
  }]
}
 dynamoDb.transactWrite(request)

Is there a reduced feature set for DynamoDB invoked lambda functions ? Or an older version of SDK used or something ?

1
Some progress, i was initializing the DocumentClient outside of the handler function, i moved the initialization inside the handler and it started to work. For the API Gateway triggered events initializing inside or outside of the handler seems to work but for the DynamoDB stream ones outside the handler does not work, anyone got any clues as to why this might be? - Mingo

1 Answers

0
votes

Try using

var dynamodb = new aws.DynamoDB();

instead of

var dynamodb = new aws.DynamoDB.DocumentClient();

Source: https://github.com/aws/aws-sdk-js/issues/2392