1. LocalStackによるインフラ構築に向けて


Quick introduction to localstack using localstack-demo

What is LocalStack ?

LocalStack provides an easy-to-use test/mocking framework for developing Cloud applications. It spins up a testing environment on your local machine that provides the same functionality and APIs as the real AWS cloud environment.

Setting up components

conda create -n localstack python=3.5
conda activate localstack
mkdir external-master
cd external-master && git clone https://github.com/good-idea/localstack-demo.git
git clone https://github.com/localstack/localstack.git
pip install awscli

Configuring

$aws configure --profile localstack
AWS Access Key ID [None]: dummy
AWS Secret Access Key [None]: dummy
Default region name [None]: us-east-1
Default output format [None]: json
$ tree .aws
.aws
├── config
└── credentials

0 directories, 2 files
$ cd .aws
$ ls
config      credentials
$ vim credentials
$ vim config

Launching localstack container

$ cd external-master/localstack-demo 
$ TMPDIR=/private$TMPDIR \
> DATA_DIR=/tmp/localstack/data \
> SERVICES=apigateway,kinesis,dynamodb,dynamodbstreams,elasticsearch,s3,\
> lambda,sns,sqs,redshift,es,ses,route53,cloudformation,cloudwatch,\
> ssm,secretsmanager,stepfunctions,logs,sts,iam,ec2 \
> docker-compose up -d
Creating network "localstack-demo_default" with the default driver
Creating localstack_demo ... done

Creating S3-bucket

Execute bellow commands after launching localstack.

aws --endpoint-url=http://localhost:4572 s3 mb s3://demo-bucket
aws --endpoint-url=http://localhost:4572 s3api put-bucket-acl --bucket demo-bucket --acl public-read

Finally, access to http://localhost:8055 and assumed result is bellow.

How to reproduce(Fastest)

Using pre-setup docker container, we can reproduce environment easily.

docker pull yoshinobusekiyu4docker/nova-dev-env:localstack
TMPDIR=/private$TMPDIR DATA_DIR=/tmp/localstack/data SERVICES=apigateway,kinesis,dynamodb,dynamodbstreams,elasticsearch,s3,lambda,sns,sqs,redshift,es,ses,route53,cloudformation,cloudwatch,ssm,secretsmanager,stepfunctions,logs,sts,iam,ec2 
docker run -it -p '4563-4599:4563-4599' -p 8055:8080 yoshinobusekiyu4docker/nova-dev-env:localstack /bin/bash -c "localstack start"
aws --endpoint-url=http://localhost:4572 s3 mb s3://demo-bucket
aws --endpoint-url=http://localhost:4572 s3api put-bucket-acl --bucket demo-bucket --acl public-read

References