'localstack docker-compose - The AWS Access Key Id you provided does not exist in our records

Running localstack and app via docker-compose to dummy a s3 bucket, but getting the error:

"msg":"Failed to upload file /test-data/test.txt: The AWS Access Key Id you provided does not exist in our records."

If i run the app via docker run using valid AWS credentials, it will run successfully and connect. Any ideas what ive done wrong?

version: '3.8'

services:
  postbox:
    build: .
    ports: 
      - "8000:8000"
    environment:
      - S3_BUCKET=localstack-postbox-s3
      - MESSAGE_BUS_ENDPOINT=http://localhost
      - AWS_REGION=eu-west-2
      - AWS_ACCESS_KEY_ID=xyz
      - AWS_SECRET_ACCESS_KEY=aaa
      - NODE_ENV=test
    depends_on:
      - localstack
    
  localstack:
    container_name: localstack
    image: localstack/localstack:0.14.2
    ports:
      - "4566-4599:4566-4599"
    environment:
      - SERVICES=s3
    volumes:
      - ./infra/localstack:/docker-entrypoint-initaws.d

  aws:
    container_name: aws-cli
    image: amazon/aws-cli:latest
    environment:
      - AWS_REGION=eu-west-2
      - AWS_ACCESS_KEY_ID=xyz
      - AWS_SECRET_ACCESS_KEY=aaa
    entrypoint: tail -f /dev/null
    depends_on:
      - localstack
      - postbox


Solution 1:[1]

Got this all working!

First ensure that endpoint_url is added for any localstack calls

Second, in the docker app ensure that any localhost calls are updated to host.docker.internal

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Staggerlee011