Skip to content

Commit a9d7b9f

Browse files
committed
adding example for Serverless App Repo Deploy Frontend Layer
1 parent 9bda2ee commit a9d7b9f

File tree

4 files changed

+88
-5
lines changed

4 files changed

+88
-5
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
DEPLOYMENT_BUCKET_NAME := desole-packaging
1+
DEPLOYMENT_BUCKET_NAME ?= desole-packaging
22
DEPLOYMENT_KEY := $(shell echo s3-deployment-$$RANDOM.zip)
33
STACK_NAME ?= s3-deployment
44

example/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ STACK_NAME ?= s3-deployment-example
33
REGION := us-east-1
44

55
clean:
6-
rm output.yml
6+
rm output-*.yml
77

8-
output.yml: template.yml web-site/*
8+
output-%.yml: template-%.yml web-site/*
99
aws cloudformation package --template-file $< --output-template-file $@ --s3-bucket=$(BUCKET_NAME) --region $(REGION)
1010

11-
deploy: output.yml
12-
aws cloudformation deploy --template-file $< --stack-name $(STACK_NAME) --capabilities CAPABILITY_IAM --region $(REGION)
11+
deploy-%: output-%.yml
12+
aws cloudformation deploy --template-file $< --stack-name $(STACK_NAME) --capabilities CAPABILITY_IAM CAPABILITY_AUTO_EXPAND --region $(REGION)
1313
aws cloudformation describe-stacks --stack-name $(STACK_NAME) --query Stacks[].Outputs[].OutputValue --output text --region $(REGION)

example/template-app-repo.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
AWSTemplateFormatVersion: 2010-09-09
2+
Transform: 'AWS::Serverless-2016-10-31'
3+
Description: Frontend Deploy Example
4+
5+
Resources:
6+
TargetBucket:
7+
Type: AWS::S3::Bucket
8+
9+
DeploymentLayer:
10+
Type: AWS::Serverless::Application
11+
Properties:
12+
Location:
13+
ApplicationId: arn:aws:serverlessrepo:us-east-1:375983427419:applications/deploy-to-s3
14+
SemanticVersion: 1.0.0
15+
16+
17+
# this function is used only during deployment,
18+
# we use the web site assets as the source of the function
19+
# tricking cloudformation to pack up the web site files
20+
# using the standard cloudformation package process
21+
SiteSource:
22+
Type: AWS::Serverless::Function
23+
Properties:
24+
Layers:
25+
# the layer contains the deployment code
26+
# so the function "source" can just contain the web assets
27+
- !GetAtt DeploymentLayer.Outputs.Arn
28+
29+
# point to directory with the assets so cloudformation can
30+
# package and upload them
31+
CodeUri: web-site/
32+
33+
# really important: this will ensure that any change in
34+
# the bundled files gets deployed again. we're abusing
35+
# the custom resource pipeline here, so this will be used
36+
# to change parameters of the resource and re-trigger it
37+
AutoPublishAlias: live
38+
39+
# the following two lines are required to make the layer work
40+
Runtime: python3.6
41+
Handler: deployer.resource_handler
42+
43+
# set the timeout to something reasonable depending on
44+
# how long it takes to upload your assets to S3
45+
Timeout: 600
46+
47+
# give the function access to the bucket where it
48+
# will upload the assets
49+
Policies:
50+
- S3FullAccessPolicy:
51+
BucketName: !Ref TargetBucket
52+
53+
# This is a custom resource that
54+
# will trigger the function during deployment
55+
DeploymentResource:
56+
Type: AWS::CloudFormation::CustomResource
57+
Properties:
58+
59+
# the following two lines are required to
60+
# ensure that cloudformation will trigger the
61+
# resource every time you change the bundled files
62+
ServiceToken: !GetAtt SiteSource.Arn
63+
Version: !Ref "SiteSource.Version"
64+
65+
# tell the deployer where to upload the files
66+
TargetBucket: !Ref TargetBucket
67+
68+
Substitutions:
69+
FilePattern: "*.html"
70+
Values:
71+
APP_NAME: 'Example Application'
72+
STACK_ID: !Ref AWS::StackId
73+
74+
# Choose the ACL and caching policies
75+
# eg, for directly accessible web site
76+
# use public-read and 10 minutes caching
77+
Acl: 'public-read'
78+
CacheControlMaxAge: 600
79+
80+
81+
Outputs:
82+
DestinationBucket:
83+
Value: !Ref TargetBucket
File renamed without changes.

0 commit comments

Comments
 (0)