2.0.0 • Published 2 years ago

aws-domain-redirect v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

aws-domain-redirect

A simple project to programmatically redirect a domain to a specific URL using AWS Route53 and AWS S3 Static Websites.


Usage

Install the node package:

yarn add aws-domain-redirect;

Redirect a Domain:

import AWSDomainRedirect from "aws-domain-redirect";
import config from "./config.js";

(async () => {
  const awsDomainRedirect = new AWSDomainRedirect(config);
  await awsDomainRedirect.Run("www.dolox.com", "dolox.com", "https://www.dolox.com/");
})();

Configuration

KeyTypeDescription
aws.accessKeyIdstringYour AWS access key ID.
aws.accessKeyIdstringYour AWS secret access key.
aws.route53.DNSNamestringThe AWS S3 Bucket DNS Name. See: https://docs.aws.amazon.com/AmazonS3/latest/userguide/WebsiteEndpoints.html
aws.route53.EvaluateTargetHealthbooleanSee: https://docs.aws.amazon.com/Route53/latest/APIReference/API_AliasTarget.html
aws.route53.HostedZoneIdstringSee: https://docs.aws.amazon.com/sdk-for-ruby/v1/api/AWS/Route53/HostedZone.html

Example:

{
  "aws": {
    "accessKeyId": "...",
    "secretAccessKey": "...",

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

API

async Run(domain, hostedZoneName, redirectUrl)

This Function will invoke the process of creating a bucket with the static website hosting redirect along with a hosted zone record.

Function Parameters:

KeyTypeDescription
domainstringThe record name for the hosted zone entry.
hostedZoneNamestringThe name of the hosted zone.
redirectUrlstringThe URL to redirect to.

The Function will return an Object on success, or will throw an error upon failure.

Return Object:

KeyTypeDescription
bucketCreateobjectResults from creating the bucket.
bucketUpdateWebsiteobjectResults from updating the bucket website.
zoneCreateobjectResults from creating the hosted zone.
zoneRecordCreateobjectResults from creating the hosted zone record.

AWS Permissions

This project needs access to programmatically:

  • Read/Write AWS Route53 Hosted Zones
  • Read/Write AWS Route53 Hosted Zone Records
  • Read/Write AWS S3 Buckets
  • Read/Write AWS S3 Static Website Redirects
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "aws-domain-redirect",
      "Effect": "Allow",
      "Action": [
        "route53:GetChange",
        "route53:GetHostedZone",
        "route53:ChangeResourceRecordSets",
        "route53:ListResourceRecordSets",
        "route53:DeleteHostedZone"
      ],
      "Resource": [
        "arn:aws:route53:::hostedzone/*",
        "arn:aws:route53:::change/*"
      ]
    },
    {
      "Sid": "VisualEditor1",
      "Effect": "Allow",
      "Action": [
        "route53:CreateHostedZone",
        "s3:GetBucketWebsite",
        "s3:PutBucketWebsite",
        "route53:ListHostedZones",
        "s3:CreateBucket",
        "s3:ListBucket"
      ],
      "Resource": "*"
    }
  ]
}

Copyright (c) 2022 Dolox, Inc.