Created
March 11, 2014 08:11
-
-
Save mechamogera/9481458 to your computer and use it in GitHub Desktop.
S3のstaticsホスティングをする構成のCloudFormationのTemplate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env ruby | |
require 'aws-sdk' | |
target = File.read(ARGV[0]) | |
cf = AWS::CloudFormation.new(proxy_uri: ENV['HTTP_PROXY'] || ENV['http_proxy']) | |
stack = cf.stacks.create('test', target) | |
while stack.status == "CREATE_IN_PROGRESS" | |
sleep 10 | |
end | |
puts stack.status | |
puts stack.status_reason |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A sample Gemfile | |
source "https://rubygems.org" | |
# gem "rails" | |
gem "aws-sdk" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"AWSTemplateFormatVersion" : "2010-09-09", | |
"Description" : "Sample", | |
"Parameters" : { | |
"StaticsDomain" : { | |
"Type" : "String", | |
"Default" : "hogemoge.test.com", | |
"Description" : "domain for statics" | |
}, | |
"StaticsHostedZone" : { | |
"Type" : "String", | |
"Default" : "test.com", | |
"Description" : "hosted zone for statics" | |
} | |
}, | |
"Resources" : { | |
"StaticsBucket" : { | |
"Type" : "AWS::S3::Bucket", | |
"Properties" : { | |
"BucketName" : { "Ref" : "StaticsDomain" }, | |
"WebsiteConfiguration" : { "IndexDocument" : "index.html", "ErrorDocument" : "error.html" } | |
} | |
}, | |
"StaticsBucketPolicy" : { | |
"Type" : "AWS::S3::BucketPolicy", | |
"Properties" : { | |
"Bucket" : { "Ref" : "StaticsBucket" }, | |
"PolicyDocument" : { | |
"Statement": [{ | |
"Effect": "Allow", | |
"Principal": { "AWS": "*" }, | |
"Action": ["s3:GetObject"], | |
"Resource": { "Fn::Join" : ["", ["arn:aws:s3:::", { "Ref" : "StaticsBucket" } , "/*" ]] }, | |
"Condition": { | |
"IpAddress": { | |
"aws:SourceIp": [ | |
"192.168.0.1/32" | |
] | |
} | |
} | |
}] | |
} | |
} | |
}, | |
"StaticsRecord" : { | |
"Type" : "AWS::Route53::RecordSet", | |
"Properties" : { | |
"HostedZoneName" : { "Fn::Join" : ["", [{ "Ref" : "StaticsHostedZone" }, "."]] }, | |
"Name" : { "Fn::Join" : ["", [{ "Ref" : "StaticsDomain" }, "."]] }, | |
"Type" : "CNAME", | |
"Comment" : "TestCreated", | |
"TTL" : "300", | |
"ResourceRecords" : [ | |
{ "Fn::Join" : ["", [{ "Ref" : "StaticsBucket" }, ".s3-website-", { "Ref" : "AWS::Region" }, ".amazonaws.com" ]] } | |
] | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env ruby | |
require 'json' | |
require 'aws-sdk' | |
target = File.read(ARGV[0]) | |
JSON.parse(target) | |
cf = AWS::CloudFormation.new(proxy_uri: ENV['HTTP_PROXY'] || ENV['http_proxy']) | |
puts cf.validate_template(target) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment