Localstack with docker compose

Localstack

Why LocalStack ?

  • Local stack allows developers to test their applications in their local environment
  • No need to deploy the application to the AWS services
  • It will save development cost of the application
  • Easy to debug the applications which depends on the various AWS resources.

summary: A fully functional local cloud stack. Develop and test your cloud and serverless apps offline!

Note: LocalStack supporting only AWS cloud stack.

Resources that comes with Localstack

  • ACM , API Gateway, CloudFormation, CloudWatch
  • CloudWatch Logs, DynamoDB, DynamoDB Streams
  • EC2, Elasticsearch Service, EventBridge (CloudWatch Events)
  • Firehose, IAM, Kinesis, KMS, Lambda, Redshift
  • Route53, S3, SecretsManager, SES, SNS
  • SQS, SSM, StepFunctions, STS

Pre-requisites

localstack with Docker cli

docker run --rm -it -p 4566:4566 -p 4510-4559:4510-4559 localstack/localstack

Docker Compose file for localstack - docker-compose.yml

  • create file with name docker-compose.yml and add below code to it.

version: '3.6'

services:
  localstack:
    container_name: localstack
    environment:
      - DEBUG=1
      - LOCALSTACK_HOSTNAME=localhost
      - TEST_AWS_ACCOUNT_ID=000000000000
      - AWS_DEFAULT_REGION=us-west-2
      - DOCKER_HOST=unix:///var/run/docker.sock
      - DATA_DIR=/tmp/localstack/data
      - KINESIS_STREAM_SHARDS=1
      - KINESIS_ERROR_PROBABILITY=0.0
      - KINESIS_STREAM_NAME=kinesis-stream
      - KINESIS_PROVIDER=kinesalite
    image: localstack/localstack:latest
    ports:
      - "4566:4566"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
- now, run the command docker-compose up to create the localstack container in docker. - open the browser and access the host localhost:4566/health and can expected to see below output.

{
  "features": {
    "initScripts": "initialized"
  },
  "services": {
    "acm": "available",
    "apigateway": "available",
    "cloudformation": "available",
    "cloudwatch": "available",
    "config": "available",
    "dynamodb": "available",
    "dynamodbstreams": "available",
    "ec2": "available",
    "es": "available",
    "events": "available",
    "firehose": "available",
    "iam": "available",
    "kinesis": "available",
    "kms": "available",
    "lambda": "available",
    "logs": "available",
    "redshift": "available",
    "resource-groups": "available",
    "resourcegroupstaggingapi": "available",
    "route53": "available",
    "route53resolver": "available",
    "s3": "available",
    "secretsmanager": "available",
    "ses": "available",
    "sns": "available",
    "sqs": "available",
    "ssm": "available",
    "stepfunctions": "available",
    "sts": "available",
    "support": "available",
    "swf": "available"
  },
  "version": "0.13.2"
}
  • If we are able to above output then the the locastack is working as expected.
  • Now, open the terminal and run the below command and create a bucket named user-uploads in locastack S3 service.
aws --endpoint-url http://localhost:4566 s3 mb s3://user-uploads
# Output: make_bucket: user-uploads
  • To confirm if S3 bucket is created then execute the below command
aws --endpoint-url http://localhost:4566 s3 ls
  • It will give output something like below.
2022-01-08 17:45:21 user-uploads