简体   繁体   中英

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

I guess I am making a silly coding mistake, but have been trying for more than a day. I am trying to insert records onto aurora table with the parameters received as a stream from dynamodb table.

I cant seem to set the parameters on the params object correctly. I want the sql statement and the parameters on the params object to be set outside params as the right statement depends on if it is an INSERT, MODIFY or REMOVE. Here is my code -

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);
};

Please advise!

Looking at examples in the documentation , you need to prefix the parameter placeholders with : . Like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM