sam unable to connect endpoint url
See original GitHub issuewe created a lambda function such that when it is executed it makes a entry in dynamob db local. and for it need to connect to the endpoint url 127.0.0.1:8000, but it is unable to connect with following error:-
Error JSON: {
"message": "connect ECONNREFUSED 127.0.0.1:8000",
"code": "NetworkingError",
"errno": "ECONNREFUSED",
"syscall": "connect",
"address": "127.0.0.1",
"port": 8000,
"region": "us-west-2",
"hostname": "localhost",
"retryable": true,
"time": "2017-08-30T07:56:18.509Z"
}
For testing purpose i used node and lambda-local to execute my lambda function and it is working perfectly fine. below is my lambda function and template
index.js
‘use strict’; console.log(‘starting function’);
var AWS = require(“aws-sdk”);
AWS.config.update({ region: “us-east-1”, endpoint: “http://localhost:8000” });
var dynamodb = new AWS.DynamoDB.DocumentClient();
exports.handle = function(e, ctx, callback) {
var params = { Item: { date: Date.now(), message: "Hello how are you" }, TableName: 'guestbook' }; dynamodb.put(params, function(err, data){ if(err){ callback(err, null); }else{ callback(null, data); } }); }
template :-
AWSTemplateFormatVersion : ‘2010-09-09’ Transform: AWS::Serverless-2016-10-31
Description: dynamodb Resources: dynamodb: Type: AWS::Serverless::Function Properties: Timeout: 60 Runtime: nodejs6.10 Handler: index.handle Policies: AmazonDynamoDBFullAccess
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (4 by maintainers)
I had the same problem and the only explanation I found is that the docker container is NOT running the DynamoDB Local process INSIDE the container (localhost) then is unable to reach out. My solution was to assign an IP alias to loopback to reach out using a different address to 127.0.0.1, and update the endpoint to that address, with this workaround I was able to connect to DynamoDB Local without network connection. Example:
At the command line run
ifconfig lo0 alias 172.16.123.1
Update your endpoint to use the alias and you are done
To remove the alias
ifconfig lo0 -alias 172.16.123.1
Do not forget to add “sudo” where applicable (Mac, Ubuntu, etc)
Please let me know if this works for you.
Regards
If that helps, I actually run DynamoDB Local as a Docker Container in the same Network as my Lambda functions spun up by SAM Local. From there, i simply name my DynamoDB Local container as “dynamo” and inside my code i simply connect to “dynamo”.
Some info: https://github.com/heitorlessa/sam-local-python-hot-reloading Docker network: docker network create sam-demo DynamoDB Local Container: docker run -d -v “$PWD”:/dynamodb_local_db -p 8000:8000 --network sam-demo --name dynamodb cnadiminti/dynamodb-local SAM Local using the same network: sam local start-api --docker-network sam-demo
On Sun, 17 Dec 2017 at 04:42 Tatch notifications@github.com wrote: