Skip to content
Advertisement

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!

Advertisement

Answer

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);`
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement