I want to train on Serverless with a DynamoDB local docker. However, with this code I get an empty list of tables :
import { DynamoDB, Endpoint } from "aws-sdk";
export const handler = async (event, context, cb) => {
const ddb = new DynamoDB();
if (process.env["DYNAMO_LOCAL_ENDPT"]) {
ddb.endpoint = new Endpoint(process.env["DYNAMO_LOCAL_ENDPT"]);
// the local env variable = http://localhost:8000
}
const tables = await ddb.listTables().promise();
const response = {
statusCode: 200,
body: JSON.stringify({
message: "Hello World!",
tables,
}),
};
return response;
};
But if I do the same using AWS CLI on Powershell with the command,
aws dynamodb list-tables --endpoint-url http://localhost:8000
I get the right response with my 2 tables on my docker.
Can you tell me what's wrong with my code ?
The DynamoDB docker region is the same that the one configured in your AWS CLI.
The region in your Serverless Yaml has to be the same (by default it's us-east-1) even if you work locally.