connecting AWS SAM Local with dynamodb in docker

前端 未结 6 1895
既然无缘
既然无缘 2020-12-02 13:39

I\'ve set up an api gateway/aws lambda pair using AWS sam local and confirmed I can call it successfully after running

sam local start-api

I\'ve

6条回答
  •  -上瘾入骨i
    2020-12-02 14:14

    If you are using LocalStack to run DynamoDB, I believe the correct command to use the LocalStack network for SAM is:

    sam local start-api --env-vars env.json --docker-network localstack_default
    

    And in your code, the LocalStack hostname should be localstack_localstack_1

    const dynamoDbDocumentClient = new AWS.DynamoDB.DocumentClient({
      endpoint: process.env.AWS_SAM_LOCAL ?
        'http://localstack_localstack_1:4569' :
        undefined,
    });
    

    However, I launched LocalStack using docker-compose up. Using the pip CLI tool to launch LocalStack may result in different identifiers.

提交回复
热议问题