Skip to content

Instantly share code, notes, and snippets.

@diegofcornejo
Created February 20, 2019 03:32
Show Gist options
  • Save diegofcornejo/7cd1d140d07a9d9f3ad200c94a7f306f to your computer and use it in GitHub Desktop.
Save diegofcornejo/7cd1d140d07a9d9f3ad200c94a7f306f to your computer and use it in GitHub Desktop.
Create a basic redirect system using lambda, s3 and cloudfront
#!/bin/sh
# Use -d subdomain.example.com -u https://randomtechguy.com
while getopts d:u: option
do
case "${option}"
in
d) DOMAIN=${OPTARG};;
u) URL=${OPTARG};;
esac
done
#create record
aws route53 change-resource-record-sets \
--hosted-zone-id XXXXXXXXXXXXX \
--change-batch '{ "Comment": "Basic Redirect", "Changes": [{ "Action": "CREATE", "ResourceRecordSet": { "Name": "'$DOMAIN'", "Type": "A", "AliasTarget": { "HostedZoneId": "Z2FDTNDATAQYW2", "DNSName": "dsuz9cvalgd8r.cloudfront.net", "EvaluateTargetHealth": false }}}]}' \
--profile aws-diego.cornejo
#create file
touch $DOMAIN
#upload to s3
aws s3 cp --content-type plain/text --website-redirect $URL $DOMAIN s3://pentcloud-basic-redirect/domains/$DOMAIN --profile aws-diego.cornejo
echo 'Add '$DOMAIN' CNAME en Cloudfront XXXXXXXXXXXX2'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment