docs
DNS Setting
Staging

⚠️ Start from Production first.

Domain Bought on Other Provider - Staging 🌐

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

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 for the same reason as in production—GoDaddy cannot find the subdomain created by AWS.

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

Create Permission Set

Step 5: Add NS Record

Now go to your DNS provider, which in our case is GoDaddy. We will start adding a new NS record, one by one.

Create Permission Set

Choose type NS, enter api.staging in the name field, and paste the value in the value field.

Create Permission Set

Add the remaining NS values.

Create Permission Set

Once you've added all the NS values, the DNS will propagate, and your cdk deploy will complete successfully.

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.