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:
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.
I build software and work with software teams to improve workflows, communication, and best practices. If you'd like to work together, please get in touch!
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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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:Both
endpoint
ands3ForcePathStyle
are important here.s3ForcePathStyle
tells the sdk to use url of the fromhostname/bucket
instead ofbucket.hostname
.Besides being the only configuration working for me, with this, I don't need to prepend bucketName in my params:
becomes
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!
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.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)localhost
when my app is not dockerized (happening on my CI testing job)I also got the
ECONNREFUSED
error, but while running my application outside a container. Turned out that using127.0.0.1
instead oflocalhost
in theendpoint
param was the solution. I'm on MacOS.