# Connection refused to AWS running on localstack

**URL:** <https://discourse.nodered.org/t/connection-refused-to-aws-running-on-localstack/64941>\
**Category:** General\
**Tags:** docker\
**Created:** [11 July 2022 12:06 UTC](https://discourse.nodered.org/t/connection-refused-to-aws-running-on-localstack/64941 "2022-07-11T12:06:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Huntonion](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/huntonion/32/64080_2.png) [@Huntonion](https://discourse.nodered.org/u/Huntonion)\
**Post date:** [11 July 2022 12:06 UTC](https://discourse.nodered.org/t/connection-refused-to-aws-running-on-localstack/64941/1 "2022-07-11T12:06:25Z")

</div>

Hello, i'm just trying to list my s3 buckets on node red, and I wrote a simple node js application:

```auto
var AWS = global.get('aws-sdk');
var ep = new AWS.Endpoint('http://localhost:4566');
var s3 = new AWS.S3({endpoint:ep});

s3.listBuckets(function(err,data){
    if(err) console.log(err,err.stack);
    else console.log(data.Buckets);
});

```

It works when i run `node app.js` siply from bash, but If i try to run it on a function node in node-red, I get this error:

```auto
Error: connect ECONNREFUSED 169.254.169.254:80
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1159:16) {
  message: 'Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1',
  errno: -111,
  code: 'CredentialsError',
  syscall: 'connect',
  address: '169.254.169.254',
  port: 80,
  time: 2022-07-11T11:52:37.421Z,
  originalError: {
    message: 'Could not load credentials from any providers',
    errno: -111,
    code: 'CredentialsError',
    syscall: 'connect',
    address: '169.254.169.254',
    port: 80,
    time: 2022-07-11T11:52:37.421Z,
    originalError: {
      message: 'EC2 Metadata roleName request returned error',
      errno: -111,
      code: 'ECONNREFUSED',
      syscall: 'connect',
      address: '169.254.169.254',
      port: 80,
      time: 2022-07-11T11:52:37.420Z,
      originalError: [Object]
    }
  }
} Error: connect ECONNREFUSED 169.254.169.254:80
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1159:16)

```

I tried debugging it and the endpoint looks correctly configured. I should mention I'm running both node-red and localstack through docker, and they are connected to the same docker network.

---

<div class="post-metadata">

**Author:** ![Huntonion](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/huntonion/32/64080_2.png) [@Huntonion](https://discourse.nodered.org/u/Huntonion)\
**Post date:** [11 July 2022 15:35 UTC](https://discourse.nodered.org/t/connection-refused-to-aws-running-on-localstack/64941/2 "2022-07-11T15:35:34Z")

</div>

Solved the problem: basically I tried to refer to localhost from within the container so obviously it tried to access the wrong resource. All I had to do was change from  
`http://localhost:4566`  
to  
`http://localstackContainerName:4566`

---

<div class="post-metadata">

**Author:** ![nlaha123](https://avatars.discourse-cdn.com/v4/letter/n/5f8ce5/32.png) [@nlaha123](https://discourse.nodered.org/u/nlaha123)\
**Post date:** [21 July 2022 12:40 UTC](https://discourse.nodered.org/t/connection-refused-to-aws-running-on-localstack/64941/3 "2022-07-21T12:40:59Z")

</div>

Looks like many of us face this type of connection problems with localstack. I faced issues while connecting to SQS using localstack. I needed to change the docker-compose setup of localhost container to fix it. Detail steps here [How to Solve LocalStack Always Connecting To LocalHost – W3 Spot](https://www.w3spot.com/2021/06/how-to-solve-localstack-always-connecting-to-localhost.html)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [4 August 2022 12:41 UTC](https://discourse.nodered.org/t/connection-refused-to-aws-running-on-localstack/64941/4 "2022-08-04T12:41:05Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
