@@ -6,29 +6,55 @@ Resources:
6
6
TargetBucket :
7
7
Type : AWS::S3::Bucket
8
8
9
+ # this function is used only during deployment,
10
+ # enabling cloudformation to pack up the web site source and assets
11
+ # using the standard cloudformation package process
9
12
SiteSource :
10
13
Type : AWS::Serverless::Function
11
14
Properties :
12
15
Layers :
16
+ # the layer contains the deployment code
17
+ # so the function "source" can just contain the web assets
13
18
- arn:aws:lambda:us-east-1:145266761615:layer:s3-deployment:1
19
+ # point to directory with the assets so cloudformation can
20
+ # package and upload them
14
21
CodeUri : web-site/
22
+ # really important: this will ensure that any change in
23
+ # the bundled files gets deployed again. we're abusing
24
+ # the custom resource pipeline here, so this will be used
25
+ # to change parameters of the resource and re-trigger it
15
26
AutoPublishAlias : live
27
+ # the following two lines are required to make the layer work
16
28
Runtime : python3.6
17
29
Handler : deployer.resource_handler
30
+ # set the timeout to something reasonable depending on
31
+ # how long it takes to upload your assets to S3
18
32
Timeout : 600
33
+ # give the function access to the bucket where it
34
+ # will upload the assets
19
35
Policies :
20
36
- S3CrudPolicy :
21
37
BucketName : !Ref TargetBucket
22
38
39
+ # This is a custom resource that
40
+ # will trigger the function during deployment
23
41
DeploymentResource :
24
42
Type : AWS::CloudFormation::CustomResource
25
43
Properties :
44
+ # the following two lines are requires to
45
+ # ensure that cloudformation will trigger the
46
+ # resource every time you change the bundled files
26
47
ServiceToken : !GetAtt SiteSource.Arn
27
- TargetBucket : !Ref TargetBucket
28
- Acl : ' private'
29
- CacheControlMaxAge : 700
30
48
Version : !Ref "SiteSource.Version"
49
+ # tell the deployer where to upload the files
50
+ TargetBucket : !Ref TargetBucket
51
+ # Choose the ACL and caching policies
52
+ # eg, for directly accessible web site
53
+ # use public-read and 10 minutes caching
54
+ Acl : ' public-read'
55
+ CacheControlMaxAge : 600
56
+
31
57
32
58
Outputs :
33
59
DestinationBucket :
34
- Value : !Ref TargetBucket
60
+ Value : !Ref TargetBucket
0 commit comments