0
votes

I'm using the serverless framework to work with a database, using AWS Lambda Functions. I've created the table on dynamoDb, and I want to build a CRUD for my clients. I created some clients on my table with a Lambda Function, but I cannot get an item from the table and I don't know why. Here I show my lambda function and my serverless.yml for this function.

module.exports.getClient = (event, context, callback) =>{
  

  const params = {
    Key: {
      PK: event.pathParameters.PK,
      SK: `#METADATA#${event.pathParameters.PK}`
    },
    TableName:dataTable
  };

  console.log(params);

  return db
    .get(params)
    .promise()
    .then((res) => {
      if (res.Item) callback(null, response(200, res.Item));
      else callback(null, response(404, { error: 'Cliente no encontrado' }));
    })
    .catch((err) => callback(null, response(err.statusCode, err)));
};
getClient:
    handler: handler.getClient
    events:
    - http: 
        path: /client/{PK}
        method: get
        integration: LAMBDA

Here I show my table on dynamoDb with the items I created using another lambda function on the same project.DataTable on DynamoDB

1

1 Answers

0
votes

Check the PK

  PK: `CLIENT#${event.pathParameters.PK}`,
  SK: `#METADATA#${event.pathParameters.PK}`