docs
DNS Setting
Domain bought on AWS
Staging

⚠️ Start from Production first.

Domain Bought on AWS - Staging 🌐

In this guide, we’ll walk you through setting up the subdomain, api.staging.yourdomain for staging.

⚠️ DNS deployment on Staging is a bit different. We will create a hosted zone for staging.yourdomain in the Staging account and delegate the subdomain from the Production account.

Setting Up DNS for Staging 🚀

Now that we’ve successfully setup the hosted zone for production, it’s time to set things up for staging!

Step 1: Configure Your .env File 📝

Now, let’s configure your .env file for staging.

  • Go to cdk/.env.
  • Uncomment the Staging section. Production part should be commented out.
  • Add your DOMAIN_NAME value for the staging environment. Must start with staging.yourdomain

For example,

  DOMAIN_NAME=staging.awslaunchgoat.com
Step 2: Destroy Previous Stacks 🧹

Before we deploy the new changes, let’s clean up the old stacks:

  • Run aws sso login --profile awslaunchgoat-staging to log in.
  • Run cdk destroy --qualifier launchgoat --profile awslaunchgoat-staging to delete any previously deployed stacks.
Step 3: Bootstrap and Deploy 🚀

Now that we’ve cleaned up the old stacks, let’s bootstrap and deploy the staging environment:

  1. Run cdk bootstrap --qualifier launchgoat --profile awslaunchgoat-staging to prepare your AWS environment.
  2. Then, run cdk deploy --qualifier launchgoat --require-approval never --profile awslaunchgoat-staging to deploy the new stack.
  3. Don't wait until it's finished, go to Step 4 right now.
Step 4: Very Important Part!!

After running cdk deploy, our code creates a new hosted zone for staging.yourdomain.

Create Permission Set

However, the deployment won't complete and gets stuck. This happens because for example awslaunchgoat.com is the root domain, and staging.awslaunchgoat.com is a subdomain.

DNS queries fail to resolve addresses under the subdomain because they don’t know where to direct the requests. That’s why we need to add the NS record for staging.awslaunchgoat.com in the Production account.

Let’s copy the NS record from staging.yourdomain.

Create Permission Set

Now, log in to your Production Account.

Create Permission Set

Step 5: Add NS Record

Go to the Route 53 and Hosted zones. Click on the Create record button.

Create Permission Set

Add the Record name (staging), Record type (NS), and paste the NS value. Then click on Create records.

Create Permission Set

Once you’ve added the record, the changes will propagate within a few minutes. The ACMStack will then complete in CloudFormation, and your cdk deploy will successfully finish.

Navigate to your staging URL, which should be: https://api.staging.yourdomain (opens in a new tab)

For example, in my case, it would be: https://api.staging.awslaunchgoat.com

Create Permission Set


Congratulations! 🎉

You’ve successfully set up your DNS with HTTPS! Your Staging API is now:

  • Securely accessible via HTTPS.
  • Load-balanced across your containers for better performance and reliability.