I want to create a API endpoint in Node.js that lists the table names in DynamoDB. I have created a simple table locally and confirmed the table exists with the command
aws dynamodb list-tables --endpoint-url http://host.docker.internal:8000
{
"TableNames": [
"SampleTable"
]
}
but my lambda returns
{"TableNames":[]}
here's my lambda
const AWS = require('aws-sdk');
const options = {
apiVersion: '2012-08-10',
region: 'us-east-1',
};
if (process.env.AWS_SAM_LOCAL) {
options.endpoint = new AWS.Endpoint('http://host.docker.internal:8000');
}
const ddb = new AWS.DynamoDB(options);
exports.listTablesHandler = async (event) => {
if (event.httpMethod !== 'GET') {
throw new Error(`listTables only accept GET method, you tried: ${event.httpMethod}`);
}
console.info('received:', event);
const params = {};
let response = { statusCode: '500' };
try {
response = await ddb.listTables(params).promise();
} catch (err) {
console.log(err);
}
return response;
};
I expected the Lambda to list the name "SampleTable" in the API response