执行 lambda 函数时出错 - 参数 \"userId\" 具有未设置字段的值

Getting error when executing a lambda function - Parameter \"userId\" has value with no field set

我想我犯了一个愚蠢的编码错误,但我已经尝试了一天多了。我正在尝试使用从 dynamodb table.

作为流接收的参数将记录插入到 aurora table

我似乎无法在 params 对象上正确设置参数。我希望 sql 语句和 params 对象上的参数设置在 params 之外,因为正确的语句取决于它是 INSERT、MODIFY 还是 REMOVE。这是我的代码 -

const AWS = require('aws-sdk');
var RDS = new AWS.RDSDataService();

exports.handler = async (event, context) => {
    var userId;
    var givenName;
    
    const params = {
        secretArn: 'secretArn',
        resourceArn: 'resourceArn',
        database: 'db',
        parameters: [{
                name: 'userId',
                value: {
                    "stringValue": this.userId
                }
            },
            {
                name: 'givenName',
                value: {
                    "stringValue": this.givenName
                }
            }
        ]
    };    
    let record = event['Records'];        
    if (record[0].eventName == 'INSERT') {
        params.sql = `INSERT INTO Users (UserId, GivenName) VALUES(userId, givenName);`
        userId = record[0].dynamodb.NewImage.pk.S;
        givenName = record[0].dynamodb.NewImage.sk.S;            
    }
    let result = await RDS.executeStatement(params).promise();
    return JSON.stringify(result);
};

请指教!

查看 the documentation 中的示例,您需要在参数占位符前加上前缀 :。像这样:

 params.sql = `INSERT INTO Users (UserId, GivenName) VALUES(:userId, :givenName);`