1 of 12

LocalStack Tutorial

💻 A fully functional local AWS cloud stack.�Develop and test your cloud & Serverless apps offline!

Waldemar Hummer

waldemar.hummer@gmail.com

WeAreDevelopers World Congress

Berlin, June 2019

2 of 12

What is LocalStack?

  • Framework that allows local testing of Cloud applications
  • Stubs out AWS services on the local machine (currently 22 services supported)

3 of 12

History

  • Started as a small project at Atlassian (Sydney) in late 2016
  • Jeff Barr (Chief Evangelist @ AWS) tweeted about LocalStack in March 2017

  • Meanwhile has turned into a flagship open source project
    • 17.000 stars on Github
    • Several third party projects depending on LocalStack
    • Upgrade to “Adopt” in the ThoughtWorks Technology Radar:

4 of 12

Architecture

LocalStack main process (Python)

DynamoDB Local backend

(port 4564)

DynamoDB proxy (port 4569)

S3 moto backend

(port 4563)

S3 proxy�(port 4572)

Lambda API�(port 4574)

Kinesis proxy�(port 4568)

Kinesis backend

(port 4565)

...

CloudFormation API (port 4574)

5 of 12

Recent Growth

  • Docker pulls of the localstack/localstack image
    • Apprx 5 million total Docker image pulls to date

6 of 12

Configuration Options (excerpt)

  • SERVICES: Comma-separated list of services to start (e.g., “sqs,sns,s3,es”)
  • HOSTNAME / HOSTNAME_EXTERNAL: Customize the host names
  • LAMBDA_EXECUTOR: One of “local”, “docker”, or “docker-reuse”
  • LAMBDA_REMOTE_DOCKER: Whether Lambdas are run in remote Docker
  • USE_SSL: Whether to start APIs with SSL enabled (self-signed or own certs)
  • *_ERROR_PROBABILITY: For injecting faults into Kinesis/DynamoDB APIs
  • DATA_DIR: Local directory for saving persistent data
  • DOCKER_FLAGS: Pass custom flags to “docker run …” for Lambdas
  • LAMBDA_FALLBACK_URL: Fallback URL if non-existing Lambda is invoked

7 of 12

Using the Command Line

  • Command-Line Interface “awslocal”
  • Example: Put a message on an SQS queue
    • awslocal sqs create-queue --queue-name q1
    • awslocal sqs send-message� --queue-url http://localhost:4576/queue/q1� --message-body 'hello world'
    • awslocal sqs receive-message� --queue-url http://localhost:4576/queue/q1

8 of 12

Demo Application

  • Create a simple application that simulates processing of long-running requests on AWS
  • Application is defined and deployed using the Serverless framework: http://serverless.com/
  • Make use of various AWS services:
    • API Gateway
    • Cloud Formation
    • Dynamo DB
    • Lambda
    • S3
    • SQS
    • Step Functions

QUEUED

PROCESSING

FINISHED

9 of 12

Demo Application - Architecture

LocalStack

Step Functions State Machine

Application Handler Lambda

API Gateway

REST API

Processing Lambda

Request Worker Lambda

DynamoDB Table

SQS

Request Queue

Archiving Lambda

S3 Bucket

User’s Web Browser

10 of 12

11 of 12

Running in Docker

  • Can run in practically any environment (“zero” requirements)
    • Main process and Lambda functions run in Docker
  • Mounting Lambda code into containers enables a quick dev loop

Host (e.g., Mac OS)

Docker

/path/to/lambda/handler.py

LocalStack container

Lambda container 1

/path/to/handler.py

Lambda API

mount

12 of 12

Conclusion

  • Developing cloud apps locally is feasible!
    • Allows for a very efficient dev&test loop
      • Offline testing
      • Zero costs
      • No name collisions with multiple developers
    • Caveat: Not always 100% the same conditions as in the real environment
      • Integration testing on AWS still required before pushing changes out to production
  • Future plans
    • Single entry point - proxy all APIs on a single port, instead of one port per service
    • Enable DNS resolution for custom domain names (e.g., S3 bucket names)
    • Support for more cloud APIs
    • Extend the scope beyond AWS
      • Azure Cloud, Google Cloud Platform, IBM Bluemix
    • Improve the performance and reduce the memory footprint of the stack