Tips and Tricks for Local AWS
Maria Livia Chiorean
Software Developer @ Sky
@MariaLiviaCh
Problem
(Story Time)
The Developer ^-^
A
B
C
Account 1
Account 2
-
Credentials for account 1;
-
Credentials for account 2;
-
Create testing resources for 2 DynamoDB tables, 2 S3 buckets and 1 Kinesis;
-
Add some test data;
-
Start app C;
-
Start app B;
-
Start app A.
Steps
Solution
Localstack
Docker container
with Localstack image
...
Application
Prerequisites
> brew cask install docker
> brew install docker-compose
docker-compose.yml
version: "3.7"
services:
localstack:
image: localstack/localstack
ports:
- "4569:4569"
- "4572:4572"
environment:
- SERVICES=dynamodb,s3
sbt-docker-compose plugin
addSbtPlugin("com.tapad" % "sbt-docker-compose" % "1.0.34")
lazy val root = (project in file("."))
.enablePlugins(DockerComposePlugin)
.settings(
name := "localstack-example"
)
Or simply run:
> docker-compose -d up
> sbt dockerComposeUp
Spin up docker:
Create AWS resources
> brew install awscli
> aws s3api
create-bucket
--endpoint-url=http://localhost:4572
--bucket Config
AWSTemplateFormatVersion: "2010-09-09"
Resources:
ConfigBucket:
DeletionPolicy: "Retain"
Type: "AWS::S3::Bucket"
Properties:
BucketName: "Config"
Update AWS Client
import software.amazon.awssdk.core.sync.RequestBody
import software.amazon.awssdk.services.s3.S3Client
import software.amazon.awssdk.services.s3.model.PutObjectRequest
val client = S3Client.builder()
.endpointOverride(URI.create("http://localhost:4572"))
.build()
val request = PutObjectRequest.builder()
.bucket("Config")
.key("application")
.build()
client.putObject(request, RequestBody.fromString("config data"))
Start application
Can we do better?
Write a plugin to do it for you!
Old World :(
-
Install Docker and Docker Compose
-
Write docker-compose.yml
-
Spin up Docker
-
Create resources
-
Update client to use endpoint-url
-
Run app
New World :)
-
Install Docker and Docker Compose
-
Run plugin command
-
Update client to use endpoint-url
-
Run app
The sbt-local-aws plugin
-
Spins up a docker container with localstack running.
-
Only starts up the requested AWS services.
-
Automatically creates AWS CLI resource creation commands form available cloudformation.
-
Performs cloudformation substitutions.
-
Commands for start, stop and printing out the commands.
The sbt-local-aws plugin
-
At the moment only works with DynamoDB resources.
-
Only supports yml cloudformation.
Demo
Resources
-
Localstack: https://github.com/localstack/localstack
-
sbt-local-aws: https://github.com/marialivia16/sbt-local-aws
-
Slides: @MariaLiviaCh on Twitter
Special thanks to @OscarTheLargeCat (Instagram)
Copy of Copy of Tips and Tricks for Running AWS Dependencies Locally
By Maria Livia
Copy of Copy of Tips and Tricks for Running AWS Dependencies Locally
Sphere.it 2019
- 741