Slide 1

Slide 1 text

Taming and Testing the Cloud Environment for your Java apps with LocalStack & Testcontainers 08.01.2024 Vienna

Slide 2

Slide 2 text

Anca Ghenade - Developer Advocate - [email protected] @tinyg210

Slide 3

Slide 3 text

How does one go around developing applications using AWS services?

Slide 4

Slide 4 text

A Little Story About Cloud Development

Slide 5

Slide 5 text

1. The Software Engineers are tasked with developing a new web application on AWS Cloud

Slide 6

Slide 6 text

2. Developing on a local machine, they soon find out that there are lots of dependencies with resources in the cloud

Slide 7

Slide 7 text

3. They realize that the dev & test loop is extremely slow and tedious. Every local change needs to be packaged and uploaded to the cloud for testing.

Slide 8

Slide 8 text

4. Now someone has a red build on their feature branch, but can’t efficiently test and debug their code in the CI/CD pipeline.

Slide 9

Slide 9 text

5. The whole team is using Git flow for development - one CI build per feature branch. There is an explosion of different environments required for development (branches x developers).

Slide 10

Slide 10 text

6. The manager approaches the team and complains that AWS dev/test resources are not being cleaned up properly causing cost spikes.

Slide 11

Slide 11 text

So things are kind of… complicated. 󰤆

Slide 12

Slide 12 text

Additionally…

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

5 minutes later…

Slide 15

Slide 15 text

What is LocalStack and how can it help you? A fully functional local cloud stack that was born out of these exact concerns.

Slide 16

Slide 16 text

● Enables a highly efficient dev & test loop for cloud apps ● Ships as a Docker image, easy to install and start up ● Support for 90 (-ish) services (and growing): ○ compute (Lambda, ECS, EKS) ○ various databases (DynamoDB, RDS) ○ messaging (SQS, Kinesis, MSK) ○ some sophisticated/exotic APIs (Athena, Glue) ● CI integrations & advanced collaboration features ● Branching out into other areas: Chaos Engineering, IAM Security Testing, Cloud Ephemeral Environments, 3rd Party Extensions, etc

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

https://github.com/localstack-samples/sample-shipment-list-demo-lambda-dynamodb-s3

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

Using Spring Profiles…

Slide 21

Slide 21 text

Scenario 1 (Production) Scenario 2 (Development)

Slide 22

Slide 22 text

Scenario 1 Scenario 2

Slide 23

Slide 23 text

“Your application won’t even know the difference”

Slide 24

Slide 24 text

What about integration tests?

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

Testing your application workflow

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

There are several ways to provision your infrastructure for testing.

Slide 30

Slide 30 text

1. You do everything yourself. (https://github.com/tinyg210/testcontainers-shipment-list-demo)

Slide 31

Slide 31 text

2. You use AWS CLI scripts via init hooks. (example: https://github.com/tinyg210/stack-bytes-apigw-lambda-s3)

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

3. You get inventive and run Terraform configuration files from your Java tests.

Slide 35

Slide 35 text

But maybe don’t. 󰤆

Slide 36

Slide 36 text

4. Use LocalStack Cloud Pods (https://github.com/tinyg210/testcontainers-shipment-list-cloud-pods)

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

5. Use a mix of all of the above. - export only desired services with Cloud Pods - manage other resources via SDK clients

Slide 40

Slide 40 text

What about CI?

Slide 41

Slide 41 text

● Automated Testing ● Continuous Deployment ● Integration Testing ● Code Quality Analysis ● Infrastructure as Code (IaC) Validation ● Containerization and Orchestration ● Feature Branch Testing ● Rollbacks and Blue/Green Deployments ● Performance Testing and Scalability ● Automated Documentation Generation

Slide 42

Slide 42 text

● Automated Testing ● Continuous Deployment ● Integration Testing ● Code Quality Analysis ● Infrastructure as Code (IaC) Validation ● Containerization and Orchestration ● Feature Branch Testing ● Rollbacks and Blue/Green Deployments ● Performance Testing and Scalability ● Automated Documentation Generation

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

I’ll show you some stuff

Slide 45

Slide 45 text

Your local tests…

Slide 46

Slide 46 text

In CI…

Slide 47

Slide 47 text

Some Tips and Tricks

Slide 48

Slide 48 text

Use a waiter to make sure your Lambdas are in state ACTIVE and not just created.

Slide 49

Slide 49 text

Source: https://aws.amazon.com/blogs/compute/coming-soon-expansion-of-aws-lambda-states-to-all-functions/

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

Use this nifty configuration to scan the LocalStack logs and make sure your instance is in the right state before the tests are allowed to start:

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

Streaming container output to an SLF4J logger

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

We’re giving the OPS back to the DEVS.

Slide 56

Slide 56 text

Thank You