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

368
Views
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 answers
Answer question

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 Report
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!