Getting this error when using localstack S3 and the AWS JS SDK V3:
getaddrinfo ENOTFOUND bucket-name.localhost
My Localstack docker-compose:
localstack_main:
container_name: "localstack_main"
image: localstack/localstack
ports:
- "127.0.0.1:4566:4566"
- "127.0.0.1:4572:4572"
environment:
- SERVICES=sqs:4566,s3:4572
- DEFAULT_REGION=us-east-1
- DATA_DIR=${TMPDIR:-/tmp/}localstack/data
- HOST_TMP_FOLDER=${TMPDIR:-/tmp/}localstack
volumes:
- "${TMPDIR:-/tmp}/localstack:/tmp/localstack"
- "/var/run/docker.sock:/var/run/docker.sock"
- './localstackSetup.sh:/docker-entrypoint-initaws.d/make-s3.sh'
and my S3 config:
region: EnvConfig.S3_REGION,
endpoint: 'http://localhost:4566',
Solution was to add "forcePathStyle: true" as seen here: https://qubyte.codes/blog/tip-connecting-to-localstack-s3-using-the-javascript-aws-sdk-v3 I think this removes the automatically added ".localhost" after the bucket name.
My new config for the s3 client is:
{
region: EnvConfig.S3_REGION,
endpoint: 'http://localhost:4566',
forcePathStyle: true
}
Although the first answer worked for me I then encounter another issue while trying to connect to S3. What solved it for was following this advice.
Using the formatted S3 endpoint (http://s3.localhost.localstack.cloud:4566) fixed the issue and i didn't need to use the forcePathStyle option anymore.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With