question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sam unable to connect endpoint url

See original GitHub issue

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-31

Description: dynamodb Resources: dynamodb: Type: AWS::Serverless::Function Properties: Timeout: 60 Runtime: nodejs6.10 Handler: index.handle Policies: AmazonDynamoDBFullAccess

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

27reactions
splityocommented, Aug 31, 2017

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

3reactions
heitorlessacommented, Dec 17, 2017

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 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 ?

— 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 .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot endpoint URL connection error in Amazon S3
I'm trying to run the cp or sync command on my Amazon Simple Storage Service (Amazon S3) bucket. However, I'm getting the "Could...
Read more >
AWS S3 CLI - Could not connect to the endpoint URL
In your case, the URL says "https://s3.us-east-1a.amazonaws.com/" ... EndpointConnectionError: Could not connect to the endpoint URL: ...
Read more >
Troubleshoot endpoint URL connection error in Amazon S3
I'm trying to run the cp or sync command on my Amazon Simple Storage Service (Amazon S3) bucket. However, I'm getting the "Could...
Read more >
Troubleshoot Could not connect to endpoint URL error when I ...
... Knowledge Center article with this video: https://aws.amazon.com/premiumsupport/knowledge-center/s3- could-not - connect - endpoint - url /0...
Read more >
AWS CLI - couldn t connect to endpoint URL - Edureka
You probably have something wrong in your default profile for the default region. Check your file at ~/.aws/config, you have something like.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found