Pariyawit

http://host.docker.internal:8000

You need to set endpoint as “http://host.docker.internal:8000" because AWS SAM is running on docker but DynamoDB is running on localhost:8000.

If you put only “localhost:8000” then SAM will connect to localhost of the container whereas “host.docker.internal” will connect to localhost of the host

NodeJS example

import { DynamoDB } from 'aws-sdk';const docClient = process.env.AWS_SAM_LOCAL == 'true'? new DynamoDB.DocumentClient({endpoint: 'http://host.docker.internal:8000',}) : new DynamoDB.DocumentClient();

AWS_SAM_LOCAL is an environment variable. It is true when SAM is running locally.

--

--