Skip to content

Instantly share code, notes, and snippets.

@claytantor
Last active April 21, 2020 12:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save claytantor/324799e65ae56bc61c05b7a706ae5046 to your computer and use it in GitHub Desktop.
Save claytantor/324799e65ae56bc61c05b7a706ae5046 to your computer and use it in GitHub Desktop.
create a subdomain using a CF template
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "AWS CloudFormation Template Route53_CNAME. This uses the patameters to create a subdomain CNAME",
"Parameters" : {
"HostedZone" : {
"Type" : "String",
"Description" : "The DNS name of an existing Amazon Route 53 hosted zone",
"AllowedPattern" : "(?!-)[a-zA-Z0-9-.]{1,63}(?<!-)",
"ConstraintDescription" : "must be a valid DNS zone name."
},
"SubdomainParam": {
"Type": "String",
"Description": "Enter the subdomain name for the stack you want mapped to the CNAME"
},
"LoadBalancerParam": {
"Type": "String",
"Description": "Enter the loadbalancer name for the stack you want mapped to the CNAME"
}
},
"Resources" : {
"SubdomainDNSRecord" : {
"Type" : "AWS::Route53::RecordSet",
"Properties" : {
"HostedZoneName" : { "Fn::Join" : [ "", [{"Ref" : "HostedZone"}, "." ]]},
"Comment" : "CNAME redirect to subdomain.",
"Name" : { "Fn::Join" : [ "", [{"Ref" : "SubdomainParam"}, ".", {"Ref" : "HostedZone"}, "."]]},
"Type" : "CNAME",
"TTL" : "900",
"ResourceRecords" : [{
"Ref": "LoadBalancerParam"
}]
}
}
},
"Outputs" : {
"CNAME" : {
"Description" : "Fully qualified domain name",
"Value" : { "Ref" : "SubdomainDNSRecord" }
}
}
}
#!/usr/bin/env bash
aws cloudformation create-stack --profile default --stack-name stage-blog-cname \
--template-body file:///Users/claytongraham/data/github/dronze/dronze-cicd/cf/r53_cname.json \
--parameters ParameterKey=HostedZone,ParameterValue=dronze.com \
ParameterKey=SubdomainParam,ParameterValue=stage.blog \
ParameterKey=LoadBalancerParam,ParameterValue=dronze-elb-PROD-1699664721.us-west-2.elb.amazonaws.com
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "cloudformation:*",
"Effect": "Allow",
"Resource": "arn:aws:cloudformation:us-west-2:715212546939:stack/*"
},
{
"Action": "route53:*",
"Effect": "Allow",
"Resource": "arn:aws:route53:::hostedzone/Z3VRQF6A9GQX5I"
},
{
"Action": "codepipeline:*",
"Effect": "Allow",
"Resource": "*"
}
]
}
@claytantor
Copy link
Author

Basic pattern to create a CNAME via CF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment