Home > Net >  localstack AWS S3 javascript error : getaddrinfo ENOTFOUND bucketname.localhost
localstack AWS S3 javascript error : getaddrinfo ENOTFOUND bucketname.localhost

Time:11-12

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',

CodePudding user response:

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
  }
  • Related