Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

210
Views
Add a string to my Lambda function variable

I am trying to implement a DynamoDB single table design. I have a Lambda that's triggered by a new Cognito user with a Post Confirmation Trigger which sends the new User to my DynamoDB Table.

In the 'Item' I would like to add a string that goes before the User Sub ID which is saved to 'PK' but can't work out how to append this to the beginning.

var aws = require('aws-sdk');
var ddb = new aws.DynamoDB({apiVersion: '2012-10-08'});

exports.handler = async (event, context) => {
console.log(event);

let date = new Date();

const tableName = 'Kaleido';
const region = 'ap-southeast-2';

console.log("table=" + tableName + " -- region=" + region);

aws.config.update({region: region});

// If the required parameters are present, proceed
if (event.request.userAttributes.sub) {

    // -- Write data to DDB
    let ddbParams = {
        Item: {
            //Add 'User#' below
            "PK": {S: event.request.userAttributes.sub},
            "SK": {S: event.userName},
            "Type": "User",
            "createdAt": {S: date.toISOString()},
        },
        TableName: 'Kaleido'
    };

    // Call DynamoDB
    try {
        await ddb.putItem(ddbParams).promise();
        console.log("Success");
    } catch (err) {
        console.log("Error", err);
        context.done(null, event);
    }

    console.log("Success: Everything executed correctly");
    context.done(null, event);

} else {
    // Nothing to do, the user's email ID is unknown
    console.log("Error: Nothing was written to DDB or SQS");
    context.done(null, event);
}

};

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!