CloudFormation template for creating the AWS components for redirection to another domain, using Cloudfront and Lambda@Edge, with a custom redirection code
-
Create S3 bucket to store the packaged code used in deployment of Lambda Edge function.
The cloudformation template can be deployed directly using cli. Two steps are required: packaging the template to upload the lambda function code and creating the stack.
aws cloudformation package --template-file ./template.yml --s3-bucket s3-bucket-name --output-template-file out.yml
aws cloudformation create-stack --stack-name checkpoint --template-body file://out.yml \
--parameters \
ParameterKey=CdnCertificateArn,ParameterValue=source-domain-wildcard-cert-arn \
ParameterKey=DestinationDomain,ParameterValue=destination-domain \
ParameterKey=ZoneName,ParameterValue=source-zone-name \
ParameterKey=ZoneSubdomain,ParameterValue=source-zone-subdomain
--capabilities CAPABILITY_IAM CAPABILITY_AUTO_EXPAND
Following parameters are available for customization. Defaults can be set in the template, and can be overridden via cli as mentioned in the Template Deployment.
CdnCertificateArn:
Type: String
Description: ARN of the wildcard certificate for source domain
DestinationDomain:
Type: String
Description: The Domain of the destination to redirect requests
EnableLogs:
Type: String
Description: Lambda@Edge creates logs in multiple locations based on traffic. Switch to enable/disable logs
AllowedValues:
- true
- false
Default: true
StatusCode:
Type: Number
Description: The status code of the redirect
AllowedValues:
- 301
- 302
Default: 301
ZoneName:
Type: String
Description: Source zone name
ZoneSubdomain:
Type: String
Description: Source zone subdomain
See the LICENSE file.
From the team at QRStuff with ❤️ for automation with Cloudformation.