Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

212
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda