【问题标题】:Timing out while trying to access DynamoDB locally [duplicate]尝试在本地访问 DynamoDB 时超时 [重复]
【发布时间】:2020-01-22 09:42:46
【问题描述】:

我可以使用我的代码访问 AWS 上的 DynamoDB。我可以使用 CLI 访问本地 DynamoDB。但我无法让两人互相交谈。

# deploying dynamodb
docker run \
    --detach \
    --tty \
    --interactive \
    --publish 8000:8000 \
    --name lokal_dynamodb amazon/dynamodb-local

# deploying Go with SAM
sam local start-api \
    --template sam/template.yaml \
    --region eu-central-1 \
    --profile default

创建会话

sess, err := session.NewSessionWithOptions(session.Options{
    // Provide SDK Config options, such as Region.
    Config: aws.Config{
        Endpoint: aws.String("http://localhost:8000/"),
        Region:   aws.String("eu-central-1"),
    },
})
if err != nil {
    logger.Println(err)
    return nil
}

返回错误

unction 'ShopFunction' timed out after 20 seconds
Function returned an invalid response (must include one of: body, headers, multiValueHeaders or statusCode in the response object). Response received: 
2019-09-21 21:22:03 127.0.0.1 - - [21/Sep/2019 21:22:03] "GET /shop/f10b7ab5-9508-4cfd-acb2-efb2299dd460 HTTP/1.1" 502 -

【问题讨论】:

    标签: amazon-web-services go amazon-dynamodb aws-sam-cli amazon-dynamodb-local


    【解决方案1】:

    由于某些原因,SAM lambda 无法连接到 localhost DynamoDB,因此您需要创建一个它们引用的环回 IP 地址来访问它。

    ifconfig lo0 alias 172.16.123.1
    

    然后将您的会话配置更新为:

    sess, err := session.NewSessionWithOptions(session.Options{
        // Provide SDK Config options, such as Region.
        Config: aws.Config{
            Endpoint: aws.String("http://172.16.123.1:8000/"),
            Region:   aws.String("eu-central-1"),
        },
    })
    if err != nil {
        logger.Println(err)
        return nil
    }
    

    https://github.com/awslabs/aws-sam-cli/issues/102#issuecomment-326177151

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-18
      • 2020-08-03
      • 2015-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多