Skip to content

Instantly share code, notes, and snippets.

@jedsundwall
Created August 19, 2016 19:34
Show Gist options
  • Save jedsundwall/8bba0bc2050184bfd77e1b8232906036 to your computer and use it in GitHub Desktop.
Save jedsundwall/8bba0bc2050184bfd77e1b8232906036 to your computer and use it in GitHub Desktop.
CloudFormation template to create AWS Public Dataset
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "This template creates the AWS infrastructure to publish a public data set on S3. It creates an S3 bucket for the dataset, an S3 bucket for access logs, and a policy to allows the Amazon Public Data Set program to read the logs and the public to read the dataset.",
"Outputs": {},
"Parameters": {
"DataSetName": {
"AllowedPattern": "[a-z0-9\\.\\-_]*",
"ConstraintDescription": "may only contain lowercase letters, numbers, and ., -, or _ characters",
"Description": "The name of the dataset's S3 bucket. This will be used to create the dataset and log S3 bucket.",
"MaxLength": "250",
"MinLength": "1",
"Type": "String"
}
},
"Resources": {
"DataSetBucket": {
"DeletionPolicy": "Retain",
"DependsOn": "LogBucket",
"Properties": {
"BucketName": {
"Ref": "DataSetName"
},
"LoggingConfiguration": {
"DestinationBucketName": {
"Fn::Join": [
"",
[
{
"Ref": "DataSetName"
},
"-logs"
]
]
}
}
},
"Type": "AWS::S3::Bucket"
},
"DataSetBucketPolicy": {
"Properties": {
"Bucket": {
"Ref": "DataSetBucket"
},
"PolicyDocument": {
"Statement": [
{
"Action": [
"s3:List*",
"s3:Get*"
],
"Effect": "Allow",
"Principal": "*",
"Resource": [
{
"Fn::Join": [
"",
[
"arn:aws:s3:::",
{
"Ref": "DataSetBucket"
},
"/*"
]
]
},
{
"Fn::Join": [
"",
[
"arn:aws:s3:::",
{
"Ref": "DataSetBucket"
}
]
]
}
]
}
]
}
},
"Type": "AWS::S3::BucketPolicy"
},
"LogBucket": {
"DeletionPolicy": "Retain",
"Properties": {
"AccessControl": "LogDeliveryWrite",
"BucketName": {
"Fn::Join": [
"",
[
{
"Ref": "DataSetName"
},
"-logs"
]
]
}
},
"Type": "AWS::S3::Bucket"
},
"LogBucketPolicy": {
"Properties": {
"Bucket": {
"Ref": "LogBucket"
},
"PolicyDocument": {
"Statement": [
{
"Action": [
"s3:*"
],
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::179236797957:root"
},
"Resource": [
{
"Fn::Join": [
"",
[
"arn:aws:s3:::",
{
"Ref": "LogBucket"
},
"/*"
]
]
},
{
"Fn::Join": [
"",
[
"arn:aws:s3:::",
{
"Ref": "LogBucket"
}
]
]
}
]
}
]
}
},
"Type": "AWS::S3::BucketPolicy"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment