Domain Bought on AWS - Production 🌐
In this guide, we’ll walk you through setting up the subdomain, api.yourdomain
for production. You'll configure DNS records in AWS Route 53 to manage effectively.
Purchasing a New Domain on AWS 🛒
-
Login to
Production
account. -
Search Route 53 in the AWS Management Console.
-
Under the Registered Domains section, click on Register domains.
-
Search for your preferred domain, select it, and complete the registration process.
-
Once registered, Route 53 will automatically create a Hosted Zone for your domain. This hosted zone is where you’ll configure DNS records for both production and staging environments.
Setting Up DNS for Production 🚀
Now that we’ve successfully bought the domain, it’s time to set things up for production!
Step 1: Get Your Hosted zone ID 🔑
Copy your Hosted zone ID.
Step 2: Update acm-stack.ts
⚙️
Open cdk/lib/nested/acm-stack.ts
and paste your hosted zone ID.
Step 3: Update cdk-stack.ts
⚙️
Go to cdk/lib/cdk-stack.ts
and uncomment ACMStack
Go below and uncomment the ECSStack
part
Step 4: Update ecs-stack.ts
⚙️
Go to cdk/lib/nested/ecs-stack.ts
and update accordingly. It's just a matter of commenting out and uncommenting.
Step 5: Configure Your .env
File 📝
Now, let’s configure your .env
file for production.
- Go to
cdk/.env
. - Uncomment the Production section. Staging part should be commented out.
- Add your domain name value for the production environment. Don't add https://
For example,
Step 6: Destroy Previous Stacks 🧹
Before we deploy the new changes, let’s clean up the old stacks:
- Run
aws sso login --profile awslaunchgoat-prod
to log in. - Run
cdk destroy --qualifier launchgoat --profile awslaunchgoat-prod
to delete any previously deployed stacks.
Step 7: Bootstrap and Deploy 🚀
Now that we’ve cleaned up the old stacks, let’s bootstrap and deploy the production environment:
- Run
cdk bootstrap --qualifier launchgoat --profile awslaunchgoat-prod
to prepare your AWS environment. - Then, run
cdk deploy --qualifier launchgoat --require-approval never --profile awslaunchgoat-prod
to deploy the new stack.
Once deployment is complete, navigate to your production URL, which should be: https://api.yourdomain (opens in a new tab)
For example, in my case, it would be: https://api.awslaunchgoat.com
Congratulations! 🎉
You’ve successfully set up your DNS with HTTPS! Your API is now:
- Securely accessible via HTTPS.
- Load-balanced across your containers for better performance and reliability.
Isn’t that awesome? 😄 You’ve got a secure and scalable setup ready for production!