首页 > 解决方案 > DynamoDB 客户端错误 - TypeError: n.transactWrite 不是函数\n

问题描述

我正在尝试使用节点 sdk 中的 DynamoDB transactWrite 函数(https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html#transactWrite-property

对于 API Gateway 触发的我的 lambda 函数,该函数按预期工作,但对于我的 DynamoDB Stream 事件调用的 lambda 函数,我收到以下错误。

TypeError: n.transactWrite is not a function\n

所有 Lambda 函数都在 10.X 运行时。

下面是一个示例,说明我如何使用虚拟数据调用函数以进行说明。


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)

DynamoDB 调用的 lambda 函数是否有减少的功能集?还是使用旧版本的 SDK 之类的?

标签: typescriptamazon-dynamodbaws-sdk-nodejs

解决方案


尝试使用

var dynamodb = 新 aws.DynamoDB();

代替

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

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


推荐阅读