Skip to content

Barebones example of doing URL redirects + request country infromation using AWS Lambda@Edge and Terraform

Notifications You must be signed in to change notification settings

nossbigg/aws-lambda-edge-redirect-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aws-lambda-edge-redirect-example

This repository is a barebones example of using Terraform to provision an AWS Lambda@Edge deployment that performs a redirect and adds CloudFront-Viewer-Country to the redirected URL.

Prerequisites

1. AWS

  • AWS CLI
    • Install CLI: guide
    • Configure CLI with API Keys and Profile: guide
    • Change provider.profile in terraform/provider.tf to match the name of your own profile

2. Terraform

  • Terraform CLI
    • Install CLI: guide
    • Configure with API Token: guide
  • Terraform Organization + Workspace
    • Create own organization: guide
    • Update organization value in terraform/state.tf to own organization name
    • Create workspace with name aws-lambda-edge-redirect-example: guide
    • Set workspace Execution Mode to Local: guide

Usage

  • (Optional) You can change the URL to redirect to by changing the redirectUrl declared in lambda_logic/lambda_cf.js
  • Go to terraform/ and do terraform apply to provision the Lambda@Edge infrastructure
  • Use aws cloudfront list-distributions to list all existing distributions
  • Copy the Item.DomainName of the newly-provisioned CloudFront distribution
  • Make a request to the URL using a browser
  • You should be redirected to a webpage with a countryCode query parameter appended to the end of the URL

References

About

Barebones example of doing URL redirects + request country infromation using AWS Lambda@Edge and Terraform

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published