

下記のコードをV2からv3に変更しましたが、正常に動作しません。  
エラーは下記となります。  
原因が分かるようでしたら、ご教示いただけますでしょうか？

## 出力されたエラー

[code]

    2023-10-19T00:29:03.610Z    b5e27243-cafd-4693-9c94-714fb04b21ff    ERROR   Error scanning DynamoDB table: Error: Unsupported type passed: PhoneNumber
        at convertToNative (/var/runtime/node_modules/@aws-sdk/util-dynamodb/dist-cjs/convertToNative.js:29:27)
        at /var/runtime/node_modules/@aws-sdk/util-dynamodb/dist-cjs/convertToNative.js:62:40
        at Array.reduce (<anonymous>)
        at convertMap (/var/runtime/node_modules/@aws-sdk/util-dynamodb/dist-cjs/convertToNative.js:60:58)
        at convertToNative (/var/runtime/node_modules/@aws-sdk/util-dynamodb/dist-cjs/convertToNative.js:21:28)
        at unmarshall (/var/runtime/node_modules/@aws-sdk/util-dynamodb/dist-cjs/unmarshall.js:5:77)
        at Runtime.handler (file:///var/task/index.mjs:20:20)
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    
[/code]

## aws-sdk v2を用いたコード

[code]

    const AWS = require("aws-sdk");
    const DynamoDB = new AWS.DynamoDB.DocumentClient({ region: "ap-northeast-1" });
    const tableName = 'PhoneTable';
    
    exports.handler = async (event) => {
        // 発信者番号
        const phone = event.Details.ContactData.CustomerEndpoint.Address;
        // DynamoDBの一覧取得
        const db = await DynamoDB.scan({TableName: tableName}).promise();
        // 発信者番号が一覧に存在するかどうかの確認
        const result = db.Items.some( item => {
            return (item.PhoneNumber == phone);
        });
        return { result : result };
    };
    
[/code]

## aws-sdk v3を用いたコード

[code]

    import { DynamoDBClient, ScanCommand } from "@aws-sdk/client-dynamodb";
    import { marshall, unmarshall } from "@aws-sdk/util-dynamodb";
    const region = "ap-northeast-1";
    const tableName = 'PhoneTable';
    
    const dynamodbClient = new DynamoDBClient({ region: region });
    
    export const handler = async (event) => {
        // 発信者番号
        const phone = event.Details.ContactData.CustomerEndpoint.Address;
        
        // DynamoDBの一覧取得
        const scanParams = {
            TableName: tableName,
        };
    
        try {
            const scanCommand = new ScanCommand(scanParams);
            const data = await dynamodbClient.send(scanCommand);
            const db = unmarshall(data.Items);
    
            // 発信者番号が一覧に存在するかどうかの確認
            const result = db.some(item => {
                return (item.PhoneNumber === phone);
            });
    
            return { result: result };
        } catch (error) {
            console.error("Error scanning DynamoDB table:", error);
            throw error;
        }
    };
    
[/code]


CC BY-SA 4.0
2023-10-18T08:45:59.540
96515
2023-10-19T05:33:55.257
2023-10-19T05:33:55.257
2784
55460
question
javascript aws-lambda amazon-dynamodb
Lambda SDK for JavaScriptのV3移行に伴いコードを変更したがエラーで正常に動作しない