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
});

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}`

becomes

Key: `${name}`

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)