How To Create A Subdomain In Aws
In the field of DevOps, scripting is a must skill to learn. It makes any task easier to perform, for instance, running daily backups cronjob or doing a certbot renew weekly, etc.
One day, my fellow colleague told me to create a script that can make a sub-domain in AWS Route 53 having a user input.
What are the benefits of having this kind of script?
Firstly, it will reduce your clicking around the AWS dashboard and can quickly generate any A-type or Cname record subdomain on the go.
Secondly, by doing this kind of stuff you'll learn how to make more such scripts which can automate some tasks easily.
First of all, go to your AWS management console → Route 53 and create a hosted zone for your domain.
Copy your Hosted Zone Id and save it somewhere safe.
Now head over to your terminal and configure your awscli with this command.
aws configure Enter your credentials with an appropriate region in which your working.
Now coming to the main topic of this article.
#/bin/bash read -p "Enter a subdomain: " word
echo "You entered $word"
SUB_DOMAIN=$word JSON_STRING=$( jq -n \
--arg bn "$SUB_DOMAIN" \
'{"Comment":"CREATE/DELETE/UPSERT a record ","Changes":[{"Action":"CREATE","ResourceRecordSet":{Name: $bn,"Type":"A","TTL":300,"ResourceRecords":[{"Value":"4.4.4.4"}]}}]}' ) echo $JSON_STRING > sample.json
cat sample.json
aws route53 change-resource-record-sets --hosted-zone-id Enteryourhostedzoneid --change-batch file://sample.json
Copy and save this code with "route. sh" and do not forget to replace the hosted zone id which we earlier copied from the aw route 53 panel.
Then create a sample.json file and copy-paste the below code inside the same directory where route.sh is saved.
{ "Comment": "CREATE/DELETE/UPSERT a record ", "Changes": [ { "Action": "CREATE", "ResourceRecordSet": { "Name": "a.exampledemo.com", "Type": "A", "TTL": 300, "ResourceRecords": [ { "Value": "4.4.4.4" } ] } } ] } You can change the record type and DNS value according to your need. Save the file and lastly install the below JSON processor.
sudo apt-get install jq That's it. All the configuration is done and now time for some sub-domain creation. Run the bash file with the "bash route. sh" command.
Now head over to your Route 53 Panel in the AWS and you can see the sub-domain with the same name which you entered in the terminal has been created.
Isn't this amazing?
So how actually this script works?
It is pretty simple, we are storing a user input in a variable, and then using jq we are replacing that particular stored variable inside a query.
You can also customize this script by adding another two variables for DNS values and Record Type.
Possibilities are infinite!
Will be writing more scripts and ideas related to DevOps and AWS soon.
Thank You.
👋 Join FAUN today and receive similar stories each week in your inbox! ️ Get your weekly dose of the must-read tech stories, news, and tutorials.
Follow us on Twitter 🐦 and Facebook 👥 and Instagram 📷 and join our Facebook and Linkedin Groups 💬
If this post was helpful, please click the clap 👏 button below a few times to show your support for the author! ⬇
How To Create A Subdomain In Aws
Source: https://faun.pub/how-to-create-a-user-input-sub-domain-in-aws-route-53-56a5d03dea7b
Posted by: farrelllifflosight.blogspot.com

0 Response to "How To Create A Subdomain In Aws"
Post a Comment