CodeCommitsIssuesPull requestsActionsInsightsSecurity
dev

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

utils/create_site.sh

121lines · modecode

11 years ago
1#set -e
2
3export HOST=$1
4export DEPLOY_USER=${HOST}_deploy
5
6aws s3 mb s3://$HOST --region us-east-1
7
8aws s3 website s3://$HOST --index-document index.html --error-document error.html
9
10aws s3api put-bucket-policy --bucket $HOST --policy "{
11 \"Version\": \"2008-10-17\",
12 \"Statement\": [
13 {
14 \"Sid\": \"PublicReadForGetBucketObjects\",
15 \"Effect\": \"Allow\",
16 \"Principal\": {
17 \"AWS\": \"*\"
18 },
19 \"Action\": \"s3:GetObject\",
20 \"Resource\": \"arn:aws:s3:::$HOST/*\"
21 }
22 ]
23}"
24
25export CALLER=`date +"%T"`
26
27aws cloudfront create-distribution --distribution-config "
28{
29 \"CallerReference\": \"$CALLER\",
30 \"Comment\": null,
31 \"CacheBehaviors\": {
32 \"Quantity\": 0
33 },
34 \"Logging\": {
35 \"Bucket\": null,
36 \"Prefix\": null,
37 \"Enabled\": false,
38 \"IncludeCookies\": false
39 },
40 \"Origins\": {
41 \"Items\": [
42 {
43 \"S3OriginConfig\": {
44 \"OriginAccessIdentity\": null
45 },
46 \"Id\": \"S3-$HOST\",
47 \"DomainName\": \"$HOST.s3.amazonaws.com\"
48 }
49 ],
50 \"Quantity\": 1
51 },
52 \"DefaultRootObject\": \"index.html\",
53 \"PriceClass\": \"PriceClass_All\",
54 \"Enabled\": true,
55 \"DefaultCacheBehavior\": {
56 \"TrustedSigners\": {
57 \"Enabled\": false,
58 \"Quantity\": 0
59 },
60 \"TargetOriginId\": \"S3-$HOST\",
61 \"ViewerProtocolPolicy\": \"allow-all\",
62 \"ForwardedValues\": {
63 \"Cookies\": {
64 \"Forward\": \"none\"
65 },
66 \"QueryString\": false
67 },
68 \"AllowedMethods\": {
69 \"Items\": [
70 \"GET\",
71 \"HEAD\"
72 ],
73 \"Quantity\": 2
74 },
75 \"MinTTL\": 0
76 },
77 \"ViewerCertificate\": {
78 \"CloudFrontDefaultCertificate\": true
79 },
80 \"CustomErrorResponses\": {
81 \"Quantity\": 0
82 },
83 \"Restrictions\": {
84 \"GeoRestriction\": {
85 \"RestrictionType\": \"none\",
86 \"Quantity\": 0
87 }
88 },
89 \"Aliases\": {
90 \"Items\": [
91 \"$HOST\"
92 ],
93 \"Quantity\": 1
94 }
95}"
96
97aws iam create-user --user-name $DEPLOY_USER
98aws iam put-user-policy --user-name $DEPLOY_USER --policy-name $DEPLOY_USER --policy-document "{
99 \"Version\": \"2012-10-17\",
100 \"Statement\": [
101 {
102 \"Effect\": \"Allow\",
103 \"Action\": [
104 \"s3:DeleteObject\",
105 \"s3:ListBucket\",
106 \"s3:PutObject\",
107 \"s3:PutObjectAcl\",
108 \"s3:GetObject\"
109 ],
110 \"Resource\": [
111 \"arn:aws:s3:::$HOST\", \"arn:aws:s3:::$HOST/*\"
112 ]
113 }
114 ]
115}"
116
117aws iam create-access-key --user-name $DEPLOY_USER | cat
118
119echo "Select a SSL Cert in CloudFront if applicable"
120
121echo "Site set up. You must now manually add the cloudfront distribution to your DNS configuration."