Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

371
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda