Reader small image

You're reading from  AWS CDK in Practice

Product typeBook
Published inJun 2023
PublisherPackt
ISBN-139781801812399
Edition1st Edition
Right arrow
Authors (2):
Mark Avdi
Mark Avdi
author image
Mark Avdi

Mark Avdi is an Engineer, Solutions Architect and currently the CTO of Westpoint Software Solutions. He has gained his invaluable experience through decades of coding programs, designing software, and managing complex cloud infrastructures in multiple industries with different sets of challenges using a variety of solutions. Mark is a technologist; he keeps up with the trends and believes in the power of technology as an ultimate tool to help businesses prosper and tackle problems our world currently faces.
Read more about Mark Avdi

Leo Lam
Leo Lam
author image
Leo Lam

Leo Lam is an AWS Certified Solutions Architect and the COO of Westpoint Software Solutions. While having detailed knowledge of the vast array of services AWS currently provides, he maintains the close relationship between AWS & Westpoint as partners. Leo comes from a sporting background and uses his experience to effectively integrate the dynamics of sporting philosophy into day-to-day software development to build teams and workflows that constantly deliver.
Read more about Leo Lam

View More author details
Right arrow

Complete Web Application Deployment with AWS CDK

In the previous chapter, we learned how to deploy a simple web service with AWS CDK by utilizing AWS ECS for hosting and DynamoDB as a database. We built a TODO application that created an API and a frontend React application. While we built a working full stack cloud application, there were a few problems with our deployment:

  • Neither the frontend nor the backend was secured via TLS
  • We had to copy over the API URL into the frontend and redeploy the stack to make things work
  • The frontend code was being directly served from S3 with no distributed content delivery mechanism

In addition to that, having DynamoDB as a database is somewhat cheat code. Not every web application can switch databases overnight. Perhaps you want to move the IaC part of an existing application to AWS CDK. What if this application’s database is in MySQL?

We will attempt to address these points in this chapter. In summary, in this...

Technical requirements

The source code for this chapter can be found at https://github.com/PacktPublishing/AWS-CDK-in-Practice/tree/main/chapter-4-complete-web-application-deployment-with-aws-cdk.

The Code in Action video for this chapter can be viewed at: https://packt.link/PbobK.

Since this chapter is a continuation of the previous one, the directory structure is the same but with a few modifications to the services, which we will explore in this chapter.

You will also need a domain name that is not in use. This will allow AWS to take care of DNS records of the domain, a practice you have to go through to be able to create complete and solid web applications that are backed properly by TLS certificates issued to those domains.

DNS with Route 53

Let’s say you own the domain name example.com and you would like to assign the following two DNS records to the frontend and backend portions of our TODO application:

  • frontend.example.com
  • backend.example.com

To do this, you would have to let AWS’s DNS routing service, Route 53, take care of your domain’s DNS records. You potentially have a domain name that you’ve parked and that’s not currently used. If you do, great. If not, you can always register the cheapest possible domain name to complete this section of this book.

This is important because you will never release a web application with randomly assigned load balancer URLs, the likes of which we saw in the previous chapter. AWS Route 53 also has a domain registration service. Let’s look at how it works:

  1. Sign in to the AWS console and, in the top search bar, type in Route 53. Click on the result.
  2. From the left-hand panel, click Registered...

MySQL powered by AWS RDS

In this chapter, as well as teaching you about Route 53, DNS, and certificates, we’ve also changed our main database to MySQL hosted on AWS’s Relational Database Service (RDS).

Let’s assume that you currently run a website with a MySQL database, and this book has inspired you to move to AWS and write your infrastructure code with AWS CDK. At some point, you are going to have to do a database migration. There are plenty of ways to do this with AWS, with the most complete solution being with AWS Database Migration Service.

Keeping with the theme of simplicity and giving you the tools to tackle infrastructure problems with AWS CDK, let’s go with the simplest scenario, which would essentially be an exported .sql from your current database. That said, our plan is pretty evolved and advanced and should cover most types of database migrations.

If you look in the infrastructure/lib/constructs/RDS/init directory, you will see one...

Summary

When writing this chapter, we were hoping to close the loops around a production-grade AWS CDK setup. In this chapter, we learned how to purchase domains in Route 53 and create hosted zones for them. We then went on a (necessary) wild goose chase validating a DNS to issue ACM certificates. We then realized how CDK saves us time by doing most of the work of DNS validation for us. We configured an RDS MySQL database for our TODO application, and we also learned about the importance of storing secrets safely and how to do that with CDK apps.

There are six more chapters in this book. That said, if you’ve gotten this far, you have the general knowledge to start creating awesome DevOps automations with AWS CDK. We hope the game-changing characteristics of CDK are becoming as evident to you as they are to us. In the next chapter, we will cover how to build bulletproof CI/CD pipelines for CDK applications. See you there!

lock icon
The rest of the chapter is locked
You have been reading a chapter from
AWS CDK in Practice
Published in: Jun 2023Publisher: PacktISBN-13: 9781801812399
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (2)

author image
Mark Avdi

Mark Avdi is an Engineer, Solutions Architect and currently the CTO of Westpoint Software Solutions. He has gained his invaluable experience through decades of coding programs, designing software, and managing complex cloud infrastructures in multiple industries with different sets of challenges using a variety of solutions. Mark is a technologist; he keeps up with the trends and believes in the power of technology as an ultimate tool to help businesses prosper and tackle problems our world currently faces.
Read more about Mark Avdi

author image
Leo Lam

Leo Lam is an AWS Certified Solutions Architect and the COO of Westpoint Software Solutions. While having detailed knowledge of the vast array of services AWS currently provides, he maintains the close relationship between AWS & Westpoint as partners. Leo comes from a sporting background and uses his experience to effectively integrate the dynamics of sporting philosophy into day-to-day software development to build teams and workflows that constantly deliver.
Read more about Leo Lam