Cloudformation Delivery Template

This template was built to provide a simple delivery workflow to be used in combination with the S3Bubble desktop app.

This template does the following.

1. Creates an S3 bucket
2. Adds a policy that will allow Cloudfront to acccess it
3. Adds streaming cors
4. Create a Cloudfront distribution

Download Template

Template Code
{
    "AWSTemplateFormatVersion": "2010-09-09",
    "Description": "This template was built by the S3Bubble team to focus on media delivery",
    "Metadata": {},
    "Parameters": {
        "DeliveryBucket": {
            "Description": "Delivery Bucket Name",
            "Type": "String",
            "Default": "s3bubble-ott-delivery-{random id}",
            "AllowedPattern": ".+"
        }
    },
    "Mappings": {},
    "Conditions": {},
    "Resources": {
        "CreateDeliveryBucket": {
            "Type": "AWS::S3::Bucket",
            "Properties": {
                "BucketName": {
                    "Ref": "DeliveryBucket"
                },
                "CorsConfiguration": {
                    "CorsRules": [{
                        "AllowedHeaders": ["*"],
                        "AllowedMethods": ["GET"],
                        "AllowedOrigins": ["*"],
                        "MaxAge": "3600"
                    }]
                }
            }
        },
        "CreateDeliveryBucketPolicy": {
            "Type": "AWS::S3::BucketPolicy",
            "Properties": {
                "Bucket": {
                    "Ref": "DeliveryBucket"
                },
                "PolicyDocument": {
                    "Version": "2012-10-17",
                    "Statement": [{
                        "Action": ["s3:GetObject"],
                        "Effect": "Allow",
                        "Resource": {
                            "Fn::Sub": "arn:aws:s3:::${DeliveryBucket}/*"
                        },
                        "Principal": "*"
                    }]
                }
            }
        },
        "CreateWebsiteCloudFront": {
            "Type": "AWS::CloudFront::Distribution",
            "DependsOn": ["CreateDeliveryBucket"],
            "Properties": {
                "DistributionConfig": {
                    "Comment": "Create With Cloudformation",
                    "Origins": [{
                        "DomainName": {
                            "Fn::GetAtt": ["CreateDeliveryBucket", "RegionalDomainName"]
                        },
                        "Id": {
                            "Ref": "CreateDeliveryBucket"
                        },
                        "CustomOriginConfig": {
                            "HTTPPort": "80",
                            "HTTPSPort": "443",
                            "OriginProtocolPolicy": "http-only"
                        }
                    }],
                    "Enabled": "true",
                    "DefaultCacheBehavior": {
                        "TargetOriginId": {
                            "Ref": "CreateDeliveryBucket"
                        },
                        "ViewerProtocolPolicy": "redirect-to-https",
                        "AllowedMethods": ["GET", "HEAD", "OPTIONS"],
                        "CachedMethods": ["GET", "HEAD", "OPTIONS"],
                        "Compress": false,
                        "ForwardedValues": {
                            "QueryString": "true",
                            "Cookies": {
                                "Forward": "none"
                            },
                            "Headers": ["Access-Control-Request-Headers", "Access-Control-Request-Method", "Origin"]
                        }
                    },
                    "PriceClass": "PriceClass_All",
                    "ViewerCertificate": {
                        "CloudFrontDefaultCertificate": "true"
                    }
                }
            }
        }
    },
    "Outputs": {
        "DeliveryBucket": {
            "Description": "Output Bucket Name",
            "Value": {
                "Ref": "DeliveryBucket"
            }
        },
        "CloudfrontUrl": {
            "Description": "Cloudfront Url",
            "Value": {
                "Fn::GetAtt": ["CreateWebsiteCloudFront", "DomainName"]
            }
        }
    }
}