DEV Community

Discussion on: How to fake AWS locally with LocalStack

Collapse
 
mcmule profile image
Marc Muller

Many thanks for the article!

I had troubles: my app is running in a docker container and I was getting connection refused (ECONNREFUSED) when trying to reach the localstack container. After trying a lot of config variants, I ended up with this:

AWS.config.update({
    accessKeyId: '123',
    secretAccessKey: 'xyz',
    endpoint: 'host.docker.internal:4572',
    s3ForcePathStyle: true
});
Enter fullscreen mode Exit fullscreen mode

Both endpoint and s3ForcePathStyle are important here. s3ForcePathStyle tells the sdk to use url of the from hostname/bucket instead of bucket.hostname.

Besides being the only configuration working for me, with this, I don't need to prepend bucketName in my params:

Key: `${bucketName}/${name}`
Enter fullscreen mode Exit fullscreen mode

becomes

Key: `${name}`
Enter fullscreen mode Exit fullscreen mode

This was not the intended effect (I was just trying to get a working connection between my app and the s3 container). Hope this can help someone else.

Thanks again for your article!

Collapse
 
goodidea profile image
Joseph Thomas • Edited

Hi Marc, thanks for pointing this out! I've updated the article and the demo repo with these changes.

It's still working for me when I use http://localhost:4572 as the endpoint, so I left that as-is.

Collapse
 
mcmule profile image
Marc Muller

Awesome!

With a few more experimentation, I'm now using both variants:

  • host.docker.internal when my app is dockerized (which happens when I'm TDD'ing, most of the time)
  • localhostwhen my app is not dockerized (happening on my CI testing job)
Collapse
 
marcosdiasdev profile image
Marcos Dias

I also got the ECONNREFUSED error, but while running my application outside a container. Turned out that using 127.0.0.1 instead of localhost in the endpoint param was the solution. I'm on MacOS.