Setup Spring Boot behind a load balancer using the X-Forwarded headers

If you’ve ever deployed Spring Boot behind a load balancer, you might be aware of issues coming from differences between the request into the load balancer and the request into your application. These requests will often have a different protocol, host, or port. If Spring Boot isn’t correctly setup it can lead to all sorts of mayhem, such as generating incorrect URLs for you application. In this article you’ll discover how to make use of the X-Forwarded headers passed from a load balancer to your Spring Boot application, to help your application generate URLs correctly based on the originating request....

October 12, 2020 · Tom Gregory

VPCs, subnets, and gateways - fundamentals for working with containers in AWS

Let’s be honest, for most developers getting their software written and working on their own machine and maybe a test environment is the main priority. Deploying to production? Ah, that’s another team. All the AWS network ‘stuff’ - VPCs, subnets, gateways? Someone else’s business, right? Secondary to the contents of the holy Docker image and the beautiful code within. This couldn’t be further from the truth. The current trend is to developers owning their work all the way through from concept to production....

August 31, 2020 · Tom Gregory

Prometheus service discovery for AWS ECS

Having Prometheus automatically discover your AWS ECS services makes life a lot easier since you don’t have to manage Prometheus target configurations across environments. Although Prometheus doesn’t provide it out-of-the-box, in this article you’ll discover exactly how to setup service discovery for ECS by combining a few simple tools. By the end, we’ll have a full working example with Prometheus running in AWS ECS and discovering other ECS services whose metrics we’re interested in....

June 15, 2020 · Tom Gregory

Spring Boot default metrics

Spring Boot 2’s actuator module provides monitoring and management capabilities for your application, and includes the Micrometer metrics collection facility. Micrometer comes preconfigured with many useful default metrics, and also includes the ability for you to configure your own. In this article we’ll run through the most important default metrics provided in Spring Boot, and how you can use them to more effectively highlight problems within your application. Spring Boot Actuator and Micrometer overview The Spring Boot Actuator exposes many different monitoring and management endpoints over HTTP and JMX....

May 22, 2020 · Tom Gregory

AWS SNS for CloudWatch alarm email notifications

Do you want to learn how to setup email notifications to tell you about important events that happen in CloudWatch? In this article you’ll discover how to setup the AWS Simple Notification Service (SNS) to send you emails whenever a CloudWatch alarm gets triggered. We’ll run through a full working example, setting up the alarm and SNS resources, and demonstrating the notifications coming through in real time. What is AWS SNS?...

May 1, 2020 · Tom Gregory

Shipping AWS EC2 logs to CloudWatch with the CloudWatch agent

Want to learn how to monitor EC2 logs automatically without having to manually log into servers? Well, in this article we’ll explore how to setup the CloudWatch agent on an EC2 instance to easily stream your logs to AWS. We’ll also setup a simple alarm for when the logs contain certain text that we want to watch out for, all within a worked example. Why would you want to ship your EC2 logs to CloudWatch in the first place?...

April 24, 2020 · Tom Gregory

Running Docker in Docker on Windows (Linux containers)

If you need to run Docker within a container, or in other words Docker in Docker, this can sometimes be confusing, especially in Windows where it’s not obvious how Docker is setup. In this article, we’ll be lifting the covers on Docker for Windows and exploring how to run Docker commands in containers. Note that we’ll be covering only Linux based containers in this article. UPDATED in June 2021 to use the now default Docker for Windows WSL 2 engine....

April 17, 2020 · Tom Gregory

When to use an AWS S3 VPC endpoint

What is an S3 VPC endpoint? To understand what an S3 VPC endpoint is, we first need to know what problem it solves. Imagine we want to get access to S3 from an AWS resource. In the example below, we have an EC2 instance that needs to copy a file from an S3 bucket: This works, because: the EC2 instance is in a public subnet, so has access to the internet therefore the EC2 instance can reach the AWS S3 URL to copy the file from the S3 bucket Public subnets A public subnet is simply one that has a route to the internet....

April 10, 2020 · Tom Gregory

When to create different subnets in AWS VPCs

Configuring subnets and VPCs can be confusing when you’re setting up AWS infrastructure. There’s plenty of documentation about what subnets are, and how to create them, but not necessarily when and why you’d create them. In this article you’ll learn why you’d want to create multiple subnets in the first place. First off though, here’s a quick recap of all the network related infrastructure that lives in a VPC. If you’re familiar with this, just skip to the main section of the article....

January 24, 2020 · Tom Gregory