Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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);`
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading