Code Monkey home page Code Monkey logo

api-gateway-redirect's Introduction

api-gateway-redirect

A serverless solution to handle url redirects for static sites.

Prerequisites

  • ARN to a valid Amazon Certificate Mangager (ACM) certificate that covers your FromDomain name.
  • HostedZoneId of your FromDomain's Route53 record.

Notes:

  • If you previously used your FromDomain as a CloudFront alias you must remove that before deploying this cloudformation. Domains can only be associated with 1 CloudFront distribution.
  • Ensure you don't have any existing A or AAAA Route53 records for the FromDomain, these will be created for you. If you have prior records the deployment will fail.

Setup

  • Run bash run.sh deploy <FromDomain> <ToProtocol> <ToDomain> <HostedZoneId> <AcmArnForFromDomain>
    • For example bash run.sh deploy www.mcgilldevtech.com https mcgilldevtech.com ABC123 arn:aws:acm:us-east-1:123456789012:certificate/abc123 to redirect www to your apex domain (or visa versa).
  • Be patient, deploying the AWS::ApiGateway::DomainName doesn't break any speed records!
  • Hit the FromDomain from your browser and you should be redirected to your ToDomain, including any path.

Swap out deploy with update to run again. delete to tear it all down.

What's happening during all of this?

  • When you enter www.mcgilldevtech.com in your browser Route53 directs you to API Gateway's CloudFront.
  • CloudFront 301's you to https://www.mcgilldevtech.com
  • That URL hits the lambda which pulls off the FromDomain's path, if there is one, and reconstructs the url then 301's clients to that URL. ie. www.mcgilldevtech.com/about goes to https://mcgilldevtech.com/about,..dropping the www and enforcing https

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.