DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Streamline Microservices Development With Dapr and Amazon EKS
  • Building and Integrating REST APIs With AWS RDS Databases: A Node.js Example
  • Running Serverless Service as Serverful
  • Unlocking the Power of Streaming: Effortlessly Upload Gigabytes to AWS S3 With Node.js

Trending

  • Where the Model Stops and the Code Starts: Lessons From an AI Procurement Agent
  • Hosted Code Interpreter in Spring AI: Letting OpenAI Write and Run Python via the Responses API
  • Five Common Time-Series Queries Made Simple With Enterprise Java
  • Designing a Multi-Region Kafka Cluster for Tier-0 Workloads

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Create a Subdomain Dynamically Using AWS Route 53 and Node.js

Create a Subdomain Dynamically Using AWS Route 53 and Node.js

Build your dynamic subdomain and map it to an S3 bucket with Node.js and AWS Route 53.

By 
Vijaykishan Shyamsundar
·
Updated Oct. 13, 19 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
16.8K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

domain search

Creating subdomains with AWS Route 53.

AWS provides the scalable, easy-to-use, and powerful DNS service Route 53. This service can be managed via the AWS Console or via API.

Here we are going to see how to create a subdomain dynamically and map it to an S3 bucket using Node.js.

var AWS = require('aws-sdk')
var route53 = new AWS.Route53({ accessKeyId: cred.accesskey
secretAccessKey: cred.secretkey region: cred.region}); 


Let’s take the subdomain name from the command line argument:

var subDomainName = process.argv[2];

var params = {
  ChangeBatch: {
    Changes: [
      {
        Action: "CREATE",
        ResourceRecordSet: {
          AliasTarget: { 
            DNSName: "s3-website-us-east-1.amazonaws.com",
            EvaluateTargetHealth: false,
            HostedZoneId: "********" 
          },
          Name: subDomainName,
          Type: "A"
        }
      }
      Comment: "Testing subdomain creation "
      },
      HostedZoneId: "{Replace with your TLD HoztzoneID}"// Depends on the type of resource that you want to route traffic to
     };


Ensure you have a host zone created in Route 53.

Go to AWS Route 53, click "Hosted Zones" on the left-hand menu, and click "Create Hosted Zone." Enter your domain name, mark it public, and save.

The moment you create a hosted zone, you will get a HostZoneID:

Comment: "Testing subdomain creation "},
HostedZoneId: "{Replace with your TLD HoztzoneID}"// 



which is suppose to be used in the HostedZoneID mentioned in the Alias Target is of S3:

AliasTarget: {DNSName: "s3-website-us-east-1.amazonaws.com",
EvaluateTargetHealth: false,HostedZoneId: "********" } 



It is hardcoded. 

Let’s invoke the changeResourceRecordSets  API:

route53.changeResourceRecordSets(params, function(err, data) {

if (err) console.log(err, err.stack); // an error occurred

else console.log(data);


When you click on the HostedZone, you will see a successful subdomain created pointing to your S3 bucket. We need to ensure  Name: subDomainName is your bucket name, and you will have successfully created your subdomain.

Hope this helps.

In the next article, we will see how a static web hosting bucket can be created dynamically.

AWS Node.js

Opinions expressed by DZone contributors are their own.

Related

  • Streamline Microservices Development With Dapr and Amazon EKS
  • Building and Integrating REST APIs With AWS RDS Databases: A Node.js Example
  • Running Serverless Service as Serverful
  • Unlocking the Power of Streaming: Effortlessly Upload Gigabytes to AWS S3 With Node.js

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook