Skip to content

Instantly share code, notes, and snippets.

@pottava
Last active October 29, 2018 11:22
Show Gist options
  • Save pottava/e910a83441c621f33789487e20c8f2a0 to your computer and use it in GitHub Desktop.
Save pottava/e910a83441c621f33789487e20c8f2a0 to your computer and use it in GitHub Desktop.
AWS CLI with Atlassian/LocalStack

1. Create a docker-compose.yml

version: '2.1'

services:

  localstack:
    image: atlassianlabs/localstack:0.5.0
    ports:
      - "4567-4582:4567-4582"
      - "8080:8080"
    environment:
      - AWS_ACCESS_KEY_ID=foo
      - AWS_SECRET_ACCESS_KEY=bar
      - AWS_DEFAULT_REGION=ap-northeast-1
      # SERVICES can be specified like 'kinesis,lambda:4569,sqs:4570'
      - SERVICES=${SERVICES- }
      # Error probability should be a decimal value between 0.0 and 1.0
      - KINESIS_ERROR_PROBABILITY=${KINESIS_ERROR_PROBABILITY- }
      - DYNAMODB_ERROR_PROBABILITY=${DYNAMODB_ERROR_PROBABILITY- }
      - DOCKER_HOST=unix:///var/run/docker.sock
      - DATA_DIR=/tmp/localstack
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /tmp/localstack:/tmp/localstack
    restart: always
    container_name: aws

  cli:
    image: pottava/awscli:1.11.96
    entrypoint: sh -c "apk --no-cache add bash less && tail -f /dev/null"
    environment:
      - AWS_ACCESS_KEY_ID=foo
      - AWS_SECRET_ACCESS_KEY=bar
      - AWS_DEFAULT_REGION=ap-northeast-1
    restart: always
    container_name: cli

2. Run applications

$ docker-compose up

3. Open one more terminal and attach to the CLI container

$ docker exec -it cli bash

4. Try AWS commands

bash-4.3# aws --endpoint-url=http://aws:4568 kinesis list-streams
bash-4.3# aws --endpoint-url=http://aws:4572 s3 mb s3://foo
bash-4.3# aws --endpoint-url=http://aws:4572 s3 ls
bash-4.3# exit

5. Clean the environment up

$ docker-compose down -v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment