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.

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) => {
});
}