Skip to content

Commit 6f88c15

Browse files
committedDec 10, 2016
added tmps3bucket
1 parent 4c80b4a commit 6f88c15

5 files changed

+103
-10
lines changed
 

‎.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.happypack
2-
.vscode/.browse.VC.db*
2+
.vscode
33
/node_modules
44
/server/node_modules
55
/build*

‎package.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,16 @@
7070
"build:server:serverless": "webpack --config webpack.config.server.js --env.serverless",
7171
"test:local:server": "node -e \"require('./build/lambda.js').handler(require('./server/api-gateway-event.json'), {succeed: v => console.log(v)}, (e, v) => console.log(v))\"",
7272
"flow": "flow; test $? -eq 0 -o $? -eq 2",
73-
"aws:config": "node server/configure.js $npm_package_config_accountId $npm_package_config_s3BucketName $npm_package_config_region $npm_package_config_functionName",
74-
"aws:setup": "aws s3api get-bucket-location --bucket $npm_package_config_s3BucketName --region $npm_package_config_region || yarn run aws:bucket:create && yarn run aws:package-upload-function && yarn run aws:upload-api-gateway-swagger && yarn run aws:stack:create",
75-
"aws:bucket:create": "aws s3 mb s3://$npm_package_config_s3BucketName --region $npm_package_config_region",
76-
"aws:bucket:delete": "aws s3 rm s3://$npm_package_config_s3BucketName/lambda-function.zip --region $npm_package_config_region; aws s3 rm s3://$npm_package_config_s3BucketName/simple-proxy-api.yaml --region $npm_package_config_region; aws s3 rb s3://$npm_package_config_s3BucketName --region $npm_package_config_region",
77-
"aws:upload-lambda-function-package": "aws s3 cp ./lambda-function.zip s3://$npm_package_config_s3BucketName --region $npm_package_config_region",
78-
"aws:upload-api-gateway-swagger": "aws s3 cp ./server/simple-proxy-api.yaml s3://$npm_package_config_s3BucketName --region $npm_package_config_region",
79-
"aws:stack:create": "aws cloudformation create-stack --stack-name $npm_package_config_cloudFormationStackName --template-body file://./server/cloudformation.json --capabilities CAPABILITY_IAM --parameters ParameterKey=AwsServerlessExpressS3Bucket,ParameterValue=$npm_package_config_s3BucketName --region $npm_package_config_region",
80-
"aws:stack:update": "aws cloudformation update-stack --stack-name $npm_package_config_cloudFormationStackName --template-body file://./server/cloudformation.json --capabilities CAPABILITY_IAM --parameters ParameterKey=AwsServerlessExpressS3Bucket,ParameterValue=$npm_package_config_s3BucketName --region $npm_package_config_region",
73+
"aws:config": "node server/configure.js $npm_package_config_accountId $npm_package_config_tmps3BucketName $npm_package_config_region $npm_package_config_functionName",
74+
"aws:setup": "aws s3api get-bucket-location --bucket $npm_package_config_tmps3BucketName --region $npm_package_config_region || yarn run aws:bucket:create && yarn run aws:package-upload-function && yarn run aws:upload-api-gateway-swagger && yarn run aws:stack:create",
75+
"aws:bucket:create": "aws s3 mb s3://$npm_package_config_tmps3BucketName --region $npm_package_config_region",
76+
"aws:bucket:delete": "aws s3 rm s3://$npm_package_config_tmps3BucketName/lambda-function.zip --region $npm_package_config_region; aws s3 rm s3://$npm_package_config_tmps3BucketName/simple-proxy-api.yaml --region $npm_package_config_region; aws s3 rb s3://$npm_package_config_s3BucketName --region $npm_package_config_region",
77+
"aws:upload-lambda-function-package": "aws s3 cp ./lambda-function.zip s3://$npm_package_config_tmps3BucketName --region $npm_package_config_region",
78+
"aws:upload-api-gateway-swagger": "aws s3 cp ./server/simple-proxy-api.yaml s3://$npm_package_config_tmps3BucketName --region $npm_package_config_region",
79+
"aws:stack:create": "aws cloudformation create-stack --stack-name $npm_package_config_cloudFormationStackName --template-body file://./server/cloudformation.json --capabilities CAPABILITY_IAM --parameters ParameterKey=AwsServerlessExpressS3Bucket,ParameterValue=$npm_package_config_tmps3BucketName ParameterKey=WebBucketName,ParameterValue=$npm_package_config_s3BucketName --region $npm_package_config_region",
80+
"aws:stack:update": "aws cloudformation update-stack --stack-name $npm_package_config_cloudFormationStackName --template-body file://./server/cloudformation.json --capabilities CAPABILITY_IAM --parameters ParameterKey=AwsServerlessExpressS3Bucket,ParameterValue=$npm_package_config_tmps3BucketName ParameterKey=WebBucketName,ParameterValue=$npm_package_config_s3BucketName --region $npm_package_config_region",
8181
"aws:stack:delete": "aws cloudformation delete-stack --stack-name $npm_package_config_cloudFormationStackName --region $npm_package_config_region",
82-
"aws:update-function": "aws lambda update-function-code --function-name $npm_package_config_functionName --region $npm_package_config_region --s3-bucket $npm_package_config_s3BucketName --s3-key lambda-function.zip",
82+
"aws:update-function": "aws lambda update-function-code --function-name $npm_package_config_functionName --region $npm_package_config_region --s3-bucket $npm_package_config_tmps3BucketName --s3-key lambda-function.zip",
8383
"aws:package-function": "rm -f lambda-function.zip; cd build; zip -q -r ../lambda-function.zip server.js lambda.js node_modules; cd ..",
8484
"aws:package-upload-function": "yarn run aws:package-function && yarn run aws:upload-lambda-function-package",
8585
"aws:package-upload-update-function": "yarn run aws:package-upload-function && yarn run aws:update-function"

‎server/aws-policy.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
{
55
"Effect": "Allow",
66
"Action": [
7+
"cloudfront:*",
78
"cloudformation:*",
89
"s3:*",
910
"iam:*",

‎server/cloudformation.json

+46
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
"Type": "String",
77
"Description": "The S3 bucket in which the lambda function code is stored. Bucket names are region-unique, so you must change this."
88
},
9+
"WebBucketName": {
10+
"Type": "String",
11+
"Description": "The S3 bucket in which the website code is stored."
12+
},
913
"LambdaFunctionS3Key": {
1014
"Type": "String",
1115
"AllowedPattern": ".*\\.zip",
@@ -20,6 +24,40 @@
2024
}
2125
},
2226
"Resources": {
27+
"WebBucket": {
28+
"Type": "AWS::S3::Bucket",
29+
"Properties": {
30+
"AccessControl": "PublicRead",
31+
"BucketName": { "Ref": "WebBucketName" }
32+
}
33+
},
34+
"CDN" : {
35+
"Type": "AWS::CloudFront::Distribution",
36+
"Properties" : {
37+
"DistributionConfig" : {
38+
"Origins" : [ {
39+
"DomainName": {
40+
"Fn::GetAtt": [
41+
"WebBucket",
42+
"DomainName"
43+
]
44+
},
45+
"Id" : "WebBucket",
46+
"S3OriginConfig": {}
47+
}],
48+
"Enabled" : "true",
49+
"DefaultCacheBehavior" : {
50+
"TargetOriginId": "WebBucket",
51+
"ForwardedValues" : {
52+
"QueryString" : "false"
53+
},
54+
"Compress": "true",
55+
"ViewerProtocolPolicy" : "allow-all"
56+
},
57+
"HttpVersion": "http2"
58+
}
59+
}
60+
},
2361
"ApiGatewayApi": {
2462
"Type": "AWS::ApiGateway::RestApi",
2563
"Properties": {
@@ -137,6 +175,14 @@
137175
}
138176
},
139177
"Outputs": {
178+
"S3BucketSecureURL" : {
179+
"Value" : { "Fn::Join" : [ "", [ "https://", { "Fn::GetAtt" : [ "WebBucket", "DomainName" ] } ] ] },
180+
"Description" : "URL of S3 bucket to hold website content"
181+
},
182+
"CDN" : {
183+
"Value" : { "Fn::Join" : [ "", [ "https://", { "Fn::GetAtt" : [ "CDN", "DomainName" ] } ] ] },
184+
"Description" : "URL of Cloudfront bucket to hold website content"
185+
},
140186
"LambdaFunctionConsoleUrl": {
141187
"Description": "Console URL for the Lambda Function.",
142188
"Value": {

‎server/cloudformation.json.tmpl

+46
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
"Type": "String",
77
"Description": "The S3 bucket in which the lambda function code is stored. Bucket names are region-unique, so you must change this."
88
},
9+
"WebBucketName": {
10+
"Type": "String",
11+
"Description": "The S3 bucket in which the website code is stored."
12+
},
913
"LambdaFunctionS3Key": {
1014
"Type": "String",
1115
"AllowedPattern": ".*\\.zip",
@@ -20,6 +24,40 @@
2024
}
2125
},
2226
"Resources": {
27+
"WebBucket": {
28+
"Type": "AWS::S3::Bucket",
29+
"Properties": {
30+
"AccessControl": "PublicRead",
31+
"BucketName": { "Ref": "WebBucketName" }
32+
}
33+
},
34+
"CDN" : {
35+
"Type": "AWS::CloudFront::Distribution",
36+
"Properties" : {
37+
"DistributionConfig" : {
38+
"Origins" : [ {
39+
"DomainName": {
40+
"Fn::GetAtt": [
41+
"WebBucket",
42+
"DomainName"
43+
]
44+
},
45+
"Id" : "WebBucket",
46+
"S3OriginConfig": {}
47+
}],
48+
"Enabled" : "true",
49+
"DefaultCacheBehavior" : {
50+
"TargetOriginId": "WebBucket",
51+
"ForwardedValues" : {
52+
"QueryString" : "false"
53+
},
54+
"Compress": "true",
55+
"ViewerProtocolPolicy" : "allow-all"
56+
},
57+
"HttpVersion": "http2"
58+
}
59+
}
60+
},
2361
"ApiGatewayApi": {
2462
"Type": "AWS::ApiGateway::RestApi",
2563
"Properties": {
@@ -137,6 +175,14 @@
137175
}
138176
},
139177
"Outputs": {
178+
"S3BucketSecureURL" : {
179+
"Value" : { "Fn::Join" : [ "", [ "https://", { "Fn::GetAtt" : [ "WebBucket", "DomainName" ] } ] ] },
180+
"Description" : "Name of S3 bucket to hold website content"
181+
},
182+
"CDN" : {
183+
"Value" : { "Fn::Join" : [ "", [ "https://", { "Fn::GetAtt" : [ "CDN", "DomainName" ] } ] ] },
184+
"Description" : "URL of Cloudfront bucket to hold website content"
185+
},
140186
"LambdaFunctionConsoleUrl": {
141187
"Description": "Console URL for the Lambda Function.",
142188
"Value": {

0 commit comments

Comments
 (0)
Please sign in to comment.