为什么“documentClient.put”在 DynamoDB 中执行 UPDATE 而不是 INSERT?

CSh*_*per 3 amazon-web-services node.js amazon-dynamodb typescript documentclient

我有一个简单的逻辑,我想INSERT使用 记录在表中AWS.DynamoDB.DocumentClient。下面是我正在使用的代码。在这里,我注意到.put正在更新记录,但不知道为什么。

在检查 CW 中的日志时,我没有看到任何错误,所以不确定我在这里错过了什么。

代码:

async addEvent(incomingModel: MyModel): Promise <MyModel> {
    const dynamoModel: MyModel = {
        fieldOne: incomingModel.fieldOne,
        fieldTwo: incomingModel.fieldTwo,
        "One#two#three": `${incomingModel.one}#${incomingModel.two}#${incomingModel.three}`,
        fieldThree: incomingModel.fieldThree,
        fieldFour: incomingModel.fieldFour,
    };

    var params = {
        TableName: 'Table',
        Item: dynamoModel,
    };

    return this.documentClient
        .put(params)
        .then((data) => {
            this.logger.debug(
                "Response received from Dynamo after adding an incomingModel",
                data,
                this.constructor.name,
            );

            return data as MyModel;
        })
        .catch((error) => {
            const errorMessage = JSON.stringify(error);
            this.logger.error(
                `Error creating incomingModel with body of ${errorMessage}`,
                error,
                this.constructor.name,
            );
            throw error;
        });
}
Run Code Online (Sandbox Code Playgroud)

Set*_*gan 5

这是操作的预期行为put。来自文档(强调我的):

创建新项目,或用新项目替换旧项目。如果指定表中已存在与新项目具有相同主键的项目,则新项目将完全替换现有项目。