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

365
Vistas
AWS Lambda - ValidationException: The provided key element does not match the schema

Trying to GET a single item from DynamoDB in Postman. but I keep receiving the error below from my lambda code:

"ValidationException: The provided key element does not match the schema."

const AWS = require('aws-sdk');
AWS.config.update( {
  region: 'us-east-1'
});

const dynamodb = new AWS.DynamoDB.DocumentClient();
const dynamodbTableName = 'customers';

const healthPath = '/health';
const customerPath = '/customer';

This is my lambda handler

exports.handler = async function(event, context) {
  let response;

  switch(true) {
    case event.httpMethod === 'GET' && event.path === healthPath:
      response = buildResponse(200);
      break;
    case event.httpMethod === 'GET' && event.path === customerPath:
      response = await getCustomer(event.queryStringParameters.customer_id);
      break;
    default:
      response = buildResponse(404, '404 Not Found');
  }
  return response;
}

This function GETs the info of a customer

async function getCustomer(customer_id) {
  const params = {
    TableName: dynamodbTableName,
    Key: {
      'customer_id': customer_id
    },
  }
  return await dynamodb.get(params).promise().then((response) => {
    return buildResponse(200, response.Item);
  }, (error) => {
    // THIS IS WHERE I GET THE ERORR <-------------------------------------------------------
    console.error('GET ERROR --->', error);
  });
}

This is my callback function


function buildResponse(statusCode, body) {
  return {
    statusCode: statusCode,
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(body)
  }
}

This is a picture of the schema. All attributes are strings except for customer_id and shared_id. enter image description here

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The screenshot doesn't include any information about the schema. Click "View table details" to see it. What is probably happening is that your primary key consists of a HASH key (customer id) and a RANGE key (email?). Or from a HASH key only, but not customer id (email?)

In first case, to get a customer, you need to pass both the HASH and the RANGE key.

Based on the screenshot, you need:

async function getCustomer(customer_id, email) {
  const params = {
    TableName: dynamodbTableName,
    Key: {
      'customer_id': customer_id, 'email_address': email
    },
  }
  return await dynamodb.get(params).promise().then((response) => {
    return buildResponse(200, response.Item);
  }, (error) => {

  });
}
about 4 years ago · Juan Pablo Isaza Denunciar
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