You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AWS与TypeScript新手遇编译错误:AWS.DynamoDB.Converter.unmarshall不是函数

Troubleshooting "AWS.DynamoDB.Converter.unmarshall is not a function" in TypeScript

Hey there! As someone new to AWS and TypeScript, this error is super common—usually it boils down to differences between AWS SDK v2 and v3, which have totally different module structures. Let's break down the fix step by step:

1. Confirm which AWS SDK version you're using

First, check your package.json dependencies:

  • If you see packages starting with @aws-sdk/ (like @aws-sdk/client-dynamodb), you're using SDK v3.
  • If you have a single aws-sdk dependency, that's SDK v2.

2. Fix imports for SDK v3 (most likely scenario)

SDK v3 splits functionality into smaller, modular packages—unmarshall isn't part of the main DynamoDB client anymore. Here's what you need to do:

  • Install the utility package first:
    npm install @aws-sdk/util-dynamodb
    # or yarn add @aws-sdk/util-dynamodb
    
  • Import and use unmarshall directly instead of accessing it through AWS.DynamoDB.Converter:
    import { unmarshall } from "@aws-sdk/util-dynamodb";
    import { DynamoDBStreamEvent } from "aws-lambda";
    
    export const handler = async (event: DynamoDBStreamEvent) => {
      for (const record of event.Records) {
        // Convert the DynamoDB Stream record to a JS object
        const item = unmarshall(record.dynamodb.NewImage!);
        console.log("Unmarshalled item:", item);
      }
    };
    

3. If you're using SDK v2

If you're sticking with the older v2 SDK, double-check your setup:

  • Make sure you've installed the type definitions (if you haven't already):
    npm install @types/aws-sdk --save-dev
    
  • Ensure your import and usage look like this:
    import AWS from "aws-sdk";
    
    // Optional: Initialize AWS config if needed
    AWS.config.update({ region: "your-region" });
    
    export const handler = async (event: any) => {
      for (const record of event.Records) {
        const item = AWS.DynamoDB.Converter.unmarshall(record.dynamodb.NewImage);
        console.log("Unmarshalled item:", item);
      }
    };
    
    Note: If you still see the error, check if tree-shaking or module bundling is excluding the Converter module—try importing it explicitly with import "aws-sdk/clients/dynamodb"; to ensure it's included.

4. Verify your input structure

Make sure you're passing a valid DynamoDB AttributeValue object to the unmarshall function. Stream records from DynamoDB have a structure like this:

{
  "dynamodb": {
    "NewImage": {
      "id": { "S": "123" },
      "count": { "N": "45" }
    }
  }
}

If you accidentally pass the entire record object instead of NewImage/OldImage, that could also trigger unexpected errors.

内容的提问来源于stack exchange,提问作者user8056433

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 06:55:54