Setting up an AWS CDK GitHub Actions pipeline for a Spring Boot app

I'd like to discuss what I've learned in Chapter 1 of the Stratospheric book.

In the repository stratospheric-dev/hello-stratospheric, you can check all the parts of the pipeline.

The repository consists of three major areas:

  • GitHub Actions for workflows.
  • AWS CDK to manage AWS resources.
  • Spring Boot (Docker) for publishing a new image.

GitHub Actions pipeline overview

For the pipeline, GitHub Actions can be used. There are many ways it can be organized, but in general, we want to have an automated deployment into a staging environment when a branch is merged. For changing the repository or network stack, it is fine to trigger them manually via a workflow.

Here's what it might look like. (Examples are from the Stratospheric demo repository)

Manual Steps:

  1. Bootstrap AWS CDK.
  2. Create the AWS CDK repository stack (ECR) for a specific app.
  3. Created the AWS CDK network stack (VPC, IGW, ELB, ECS).

01-bootstrap.yml
02-create-environment.yml

Automated Steps (on branch merge):

  1. Test and build the Spring Boot app.
  2. Create and push a Docker image into the AWS CDK repository stack.
  3. Deploy the AWS CDK service stack.

03-build-and-deploy.yml

As we can see, the node.js npm is executing the AWS CDK, making the GitHub Actions configuration files quite easy to read.

AWS CDK overview

The AWS CDK project can be found in main/cdk. It uses Node.js package.json file to expose available deployments, and cdk.json to provide parameters.

One interesting feature of ASW CDK is the ability to abstract and encapsulate deployment code into a construct library, which can be reused in different projects and teams.

The stratospheric-dev/cdk-constructs library will be used to import the DockerRepository, Network, ApplicationEnvironment, and Service constructs inside Java files which will create a single or multiple grouped AWS resources.

Spring Boot overview

Two things need to happen for the Spring Boot app.

First, the test and build steps need to produce a jar file, and then the docker image must be created, tagged, and pushed into ECR.

  1. Test and build the app.
  2. Create the docker image. Dockerfile
  3. Tag the images and push them to ECR.

Conclusion

This is a rough outline of the steps needed for an automated AWS CDK pipeline. The hardest part is the AWS CDK, where knowledge of individual resources, settings, and how they integrate together is important for a successful deployment.

As a side note, Cantrill - AWS Certified Solutions Architect - Associate (SAA-C03) is an excellent resource to get started with AWS, either to prepare for the exam or to gain general AWS knowledge.