Unable to connect to a Localstack docker instance on a Windows 10 machine - Unable to locate credentials

Viewed 10136

I'm trying to experiment with Localstack on a Windows 10 machine.

  • I wish to use the localstack/localstack docker image.
  • I also wish to use the amazon/aws-cli docker image for running commands against my Localstack instance. (e.g. create an S3 bucket).
  • Do not want to install python/pip on my windows machine.
  • Do not want to install aws-cli on my windows machine. (Note: I want to use docker images for aws-cli commands.)

So I seem to have Localstack running ok, but when I try and run an AWS command against the Localstack instance, I get an Unable to locate credentials error.

e.g.

CMD > docker run --rm -it amazon/aws-cli --endpoint-url=http://localhost:4566 s3 mb s3://testbucket
make_bucket failed: s3://testbucket Unable to locate credentials

and my docker file:

version: '3.2'

services:
  
  localstack:
    image: localstack/localstack # This will pull the latest
    container_name: localstack
    network_mode: bridge
    ports:
      - 4566:4566 # All servics will now go through the same port.
      - "4571:4571"
      - "${PORT_WEB_UI-8080}:${PORT_WEB_UI-8080}"
    environment:
      - SERVICES=s3
      - DEBUG=1
      - DATA_DIR=/tmp/localstack/data # This is the where the data will be stored/saved, inside the docker instance
      - PORT_WEB_UI=${PORT_WEB_UI- }
    volumes:
      - "localstack-vol:/tmp/localstack"

volumes:
  localstack-vol:

Questions

Is it possible to run an AWS command (like create an S3 bucket) from the aws-cli docker image against a Localstack instance?

Is there a way I can specify credentials?

I also have a C:\Users\<username>\.aws config and credentials file(s) with the following:

Credentials

[<snip>]
aws_access_key_id=<snip>
aws_secret_access_key=<snip>

[localstack]
aws_access_key_id = foo
aws_secret_access_key = bar


config
[profile <snip>]
region = us-west-2
role_arn = arn:aws:iam::<snip>:role/local-development
source_profile = <snip>

[profile localstack]
region = us-west-2
output = json

Can someone see what I've done wrong, please?

1 Answers

With @marcin's help, I was able to get this running:

Requirements:

Create a docker-compose.yml file

version: '3.5'

services:
  localstack:
    image: localstack/localstack # This will pull the latest
    container_name: localstack
    network_mode: bridge
    ports:
      - 4566:4566 # All servics will now go through the same port.
      - "${PORT_WEB_UI-8080}:${PORT_WEB_UI-8080}"
    environment:
      - SERVICES=s3,sns,sqs
      - DEBUG=1
      - DATA_DIR=/tmp/localstack/data # This is the where the data will be stored/saved, inside the docker instance
      - PORT_WEB_UI=${PORT_WEB_UI- }
    volumes:
      - "localstack-vol:/tmp/localstack"

volumes:
  localstack-vol:

Note: notice the name of the container: localstack. we will refer to this, later (when linking the second Docker instance, back to this).

Then run the following in the command line:

> docker-compose up

OK, in a new command line (because I like seeing the output of the instances running):

> docker run --rm -it amazon/aws-cli --version

aws-cli/2.1.21 Python/3.7.3 Linux/4.19.128-microsoft-standard docker/x86_64.amzn.2 prompt/off

So aws-cli works on localhost: nothing special yet.

Running aws-cli commands against our localstack instance

If you notice above, I've only started the following services:

  • S3
  • SNS
  • SQS

So let's make sure we can create and then list something, for each one.

### Create an S3 Bucket, then list buckets
docker run --rm -it --link localstack amazon/aws-cli --no-sign-request --endpoint-url=http://localstack:4566 s3 mb s3://mytestbucket
docker run --rm -it --link localstack amazon/aws-cli --no-sign-request --endpoint-url=http://localstack:4566 s3 ls

### Create a Topic then list topics
docker run --rm -it --link localstack amazon/aws-cli --no-sign-request --endpoint-url=http://localstack:4566 sns create-topic --name test-topic
docker run --rm -it --link localstack amazon/aws-cli --no-sign-request --endpoint-url=http://localstack:4566 sns list-topics

### Create a Queue and list queues
docker run --rm -it --link localstack amazon/aws-cli --no-sign-request --endpoint-url=http://localstack:4566 sqs create-queue --queue-name testqueue
docker run --rm -it --link localstack amazon/aws-cli --no-sign-request --endpoint-url=http://localstack:4566 sqs list-queues

enter image description here

And finally, if you wish to connect to the aws-cli Docker instance to run commands in there (e.g. something weird isn't working) then use this:

> docker run --rm -it --entrypoint /bin/bash --link localstack amazon/aws-cli

I've had to override the default entrypoint. Instead, I'm saying: "enter" the instance and run this shell (bin/bash) and let me run commands now, like I've logged into the instance.

Related