Chatwithcloud logo

ChatWithCloud

AWS GenAI Tools

Checking Why Your Route53 Domain and CloudFront Distribution Is Not Working

Amazon Web Services (AWS) provide a robust ecosystem for managing various applications and data across scalable cloud servers. This guide will help you troubleshoot why your Route53 Domain and Cloudfront Distribution may not be working as expected. We will use JavaScript and specifically Node.js AWS SDK.

Code

const AWS = require('aws-sdk'); const route53 = new AWS.Route53(); const cloudFront = new AWS.CloudFront(); async function getRoute53AndCloudfrontDistributionInfo() { const hostedZones = await route53.listHostedZonesByName().promise(); const distributions = await cloudFront.listDistributions().promise(); const distribution = distributions.DistributionList.Items.find(distribution => distribution.Aliases.Items.includes('example.com')); console.log(distribution); } getRoute53AndCloudfrontDistributionInfo();

Detailed Code Explanation

First, the script imports AWS and initialize two objects - route53 and cloudFront to make calls to Route53 and CloudFront services respectively.

Next, it creates an asynchronous function getRoute53AndCloudfrontDistributionInfo() that fetches all route53 hosted zones and Cloudfront distributions your AWS account has access to and then it finds the distribution with the alias of 'example.com'.

Finally the script logs the distribution whose alias is 'example.com'.

Expected Output Format

The expected output is a CloudFront distribution in a JSON format.

{ "CFDistributionConfig": { "CallerReference": "ExampleReference", "Aliases": { "Items": ["example.com"], "Quantity": 1 }, "DefaultRootObject": "index.html", "Origins": { // Information about the origin of your resources. }, "LastModifiedTime": "2021-08-15T16:00:00.000Z", "Id": "EDFDVBD6EXAMPLE" } }

Considerations & Caveats

This script only addresses only one distribution with the alias 'example.com'. If you have other distributions or/testing environments that aren't functioning it's recommended to extend this script or replicate it for those specific distributions.

Make sure you handle any exceptions that might occur during execution to prevent your script from crashing and to make tracking issues easier.

Required IAM Permissions and Example Policy

The script requires two specific IAM policy permissions: route53:ListHostedZonesByName and cloudfront:ListDistributions. You need to make sure the IAM role used has these permissions.

Here is an example policy:

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "route53:ListHostedZonesByName", "cloudfront:ListDistributions" ], "Resource": "*" } ] }

FAQ





Related articles
Find Out Currently Assumed Role IAM Permissions in Typescript and AWS SDK V3Find and Tag Unattached Elastic Block Storage Volumes to Optimize CostsCalculate Dynamodb Table Overprovisioned Read And Write Capacity Units Based On Last Month