we 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-31Description: dynamodb
Resources:
dynamodb:
Type: AWS::Serverless::Function
Properties:
Timeout: 60
Runtime: nodejs6.10
Handler: index.handle
Policies: AmazonDynamoDBFullAccess
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
AWS.config.update({
endpoint: "http://172.16.123.1:8000"
});
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
That's correct @splityo.
Closing this issue - @mrigankt, feel free to re-open if the above doesn't help.
Thank you 😀
On Thu 31 Aug, 2017, 4:10 PM Paul Maddox notifications@github.com wrote:
Closed #102 https://github.com/awslabs/aws-sam-local/issues/102.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/awslabs/aws-sam-local/issues/102#event-1229294866,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AGiWGj3Gm9meaDMIUQFhW-jvvccC4kPRks5sdo21gaJpZM4PHDi3
.
Is it possible to check if the alias on loopback is set correctly by calling
aws dynamodb --endpoint-url http://172.16.123.1 <any operation on DynamoDBLocal>
In other words, should it be possible to say endpoint URL is reachable from SAM Local if the command above is executable on the host machine which runs sam local start-api ?
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:
Is it possible to check if the alias on loopback is set correctly by
callingaws dynamodb --endpoint-url http://172.16.123.1
DynamoDBLocal> In other words, should it be possible to say endpoint URL is reachable
from SAM Local if the command above is executable on the host machine which
runs sam local start-api ?—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/awslabs/aws-sam-local/issues/102#issuecomment-352231659,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ADL4BFWSSEqrmQ48eVv8m-6EfZ9xX8Roks5tBJu1gaJpZM4PHDi3
.
@heitorlessa Thanks, your way of setting looks nice, I'll check that out.
For the question I posted I sorted out by myself it turns out to be true, it works fine, I just did not set the alias correctly.
Most helpful comment
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.1Update your endpoint to use the alias and you are done
To remove the alias
ifconfig lo0 -alias 172.16.123.1Do not forget to add "sudo" where applicable (Mac, Ubuntu, etc)
Please let me know if this works for you.
Regards