The Essential Guide to Public SSL Certificates in AWS: A Recipe for Secure and Trusted Web Applications Part 3
In this comprehensive blog series, we embark on a journey through the intricate landscape of domain management and SSL certificate integration within the AWS ecosystem.
In Part 1, we start from scratch, walking you through setting up your domain in AWS using Route 53. We've got step-by-step instructions and handy screenshots to make sure you're on track.
Once your domain is up and running, Part 2 shows you how to get your SSL certificates sorted. We'll cover creating and validating certificates for CloudFront and ALBs in two different AWS regions.
In the final stretch, Part 3, we'll take your setup to the next level with Infrastructure as Code (IaC). Learn how to deploy your web server with those shiny new certificates using code. Plus, we'll show you the ropes for managing certificates in the AWS console. Then we'll focus on the cleanup of the infrastructure set up in Parts 1 to 3. This essential step ensures that unused resources are removed, helping you maintain a lean and cost-effective AWS environment. Through this structured sequence, from domain registration to certificate integration, readers will gain a comprehensive understanding of the intricate processes involved in managing domains and securing them with SSL certificates within the AWS environment.
In Part 3 of our blog series, we bridge the gap between theory and practice by delving into the hands-on implementation of SSL/TLS certificates within your AWS infrastructure. Leveraging both Infrastructure as Code (IaC) and the AWS Management Console, we'll guide you through the seamless integration of these certificates with essential services such as Application Load Balancers (ALBs) and Content Delivery Networks (CDNs) like CloudFront. Building upon the foundation laid in Parts 1 and 2, where we covered domain registration and certificate acquisition.
Note: Part 1 and Part 2 are mandatory for the next steps as we will be deploying infrastructure using the certificates set up in those parts.
Let's have a look at some test infrastructure and have you deploy it.
Below you will see a diagram of the infrastructure and in what locations each service resides. Starting from the left, a user's encrypted request (port 443) navigates through Route 53, the AWS DNS service, which directs them to the nearest CloudFront(CDN) edge location(Global service). CloudFront serves cached content directly, but forwards uncached requests to the Application Load Balancer (ALB) within the region in its public subnets. The ALB acts as a secure gateway, utilising a public certificate to establish a trusted connection with the user and decrypt the incoming request. It then processes the decrypted information based on configured rules and forwards it to a healthy EC2 instance. The EC2 instance processes the request and sends its response back, which the ALB re-encrypts before returning it to the user, maintaining security throughout the journey.
A YAML file defining the Infrastructure as Code (IaC) is provided:
This file is an AWS Cloudformation (AWS IaC Service) template.
WebInfrastructure.yml: defines all the resources required for this certificate test. It sets up a basic web infrastructure including domain record, CloudFront distribution, ALB and an EC2 instance with an EBS volume. This infrastructure will then be protected by the certificates we create for the distribution and ALB. On inspection of this file, take notice of the following parameters:
To deploy CloudFormation scripts you will require an account with a setup VPC with public and private subnets. Your two created certificates as mentioned in the previous steps for your CloudFront and Application Load Balancer. You will also need the following access to deploy the script:
Read Access:
Write Access:
Note: Deploying this infrastructure will incur some costs, do remember to clean up afterwards.(~$0.93 a day) for further cost calculations/estimates navigate to AWS Price Calculator and to check your costs on your account navigate to Billing and Cost Manager.
Start by downloading the required file WebInfrastructure.yml.
Now lets deploy the infrastructure:
1. Log in to the AWS console, navigate to AWS CloudFormation console.
2. Click "Create stack", choose “With new resources” then “Template is ready” and "Upload a template file", select the provided template (WebInfrastructure.yml) and provide a Stack Name(e.g. web-infra-stack).
3. Fill Parameters: Review required parameters, enter values, and set optional parameters if desired.
Fill these in carefully, if incorrect could cause the deployment to fail.
4. Click Next.
5. Optional(highly recommended): On this page it is suggested to add a tag that will tag all the resources. Suggestions are Owner with your name as the value or System with the system name as value.
6. Review & Deploy: Review all settings, click "Create stack" to deploy, and monitor progress in the "Stacks" section.
7. Once completed and all parameters entered correctly you should be able to hit your domain and see a page with the message “It works!”
8. Notice how the url directs to https and has a padlock. Further investigation can be done by clicking on it and clicking on the certificate and seeing more information.
9. You have a basic secure https:// website!
Certificates do expire and will need to be renewed. Know when yours expires. It is important to have a valid certificate. Automated solutions can be made to warn you ahead of time. Certificate expiration warning solution using config.
To follow along and update certificates on the console, you will need a CloudFront distribution and Application Load Balancer, if previous steps were followed you will have deployed these resources via the Cloudformation(You can follow along if you have created your own resources as well).
Updating your certificate on CloudFront:
1. Navigate to your Distribution: In the CloudFront console, find the distribution you want to update the certificate for.
2. Edit Distribution Settings: Select the "Distribution Settings" tab and click "Edit" for the general settings.
3. Choose a Certificate: Under "SSL Certificate," choose "Custom SSL Certificate" and select the new certificate you want to use.
4. Specify Alternate Domain Names (Optional): If using custom domain names, add them under "Alternate Domain Names (CNAMEs)."
5. Review and Save: Double-check your changes, then click "Yes, Edit" to confirm and save the updated configuration.
6. Wait for Propagation: CloudFront will propagate the changes to its edge locations. This can take 5-15 minutes.
7. Test and Monitor: Once propagation is complete, test your website and monitor for any issues with the new certificate.
Update or add certificates to your Loadbalancer:
1. Open the Amazon EC2 console and navigate down to Load Balancing > Load Balancers in the left hand banner or can be found on the Resources banner and clicking on load balancers. Select your specific ALB name web-cert-alb (if created with provided infrastructure).
2. Go to the "Listeners and rules" tab and click on the HTTPS listener you want to update (HTTPS:443).
3. Under "Certificates", click "Add certificate" to upload a new certificate or select an existing one to "Edit".
4. Upload the new certificate file and private key (if adding), and configure Server Name Indication (SNI) if needed.
5. Review the changes and click "Save changes".
6. Wait for a short propagation period (usually under 5 minutes).
7. Test your website or application to ensure the update was successful.
A public certificate issued by ACM is eligible for automatic renewal if it meets the following criteria:
The following certificates are not eligible for automatic renewal:
NB: If left unchecked the following costs will be incurred:
Application Load Balancer fixed hourly charges (Monthly): ~$18.40
Amazon EC2 On-Demand instances cost (Monthly): ~$8.32
Amazon Elastic Block Store (EBS) total cost (Monthly): ~$0.70
CloudFront price Europe (Monthly): ~$0.21
Total Cost a Month: ~$27.63
Mathys Briers is a certified AWS DevOps Professional engineer with extensive experience implementing DevOps solutions for enterprise organizations in South Africa's retail and finance sectors. He is passionate about automated pipelines, efficient and secure release controls, and maintaining robust AWS cloud infrastructure. In his free time, he enjoys tinkering with home projects, particularly focusing on automating home tasks.
Petrus Smit is a Senior DevOps Engineer with experience in AWS implementations since 2019. He has delivered high-profile projects for various enterprise organizations in South Africa and serves as one of the Technical Leads at Autumn Leaf.