/
template.yaml
112 lines (101 loc) · 4.01 KB
/
template.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
(SO8101)
serving-based-on-device
The lambda shows how to serve different version of an object based on the type of device
that user is using.
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Timeout: 5
Tags:
Publisher: AWS
Metadata:
AWS::ServerlessRepo::Application:
Name: serving-based-on-device
Description: The Lambda@Edge is designed to serve content based on device type, for example, mobile device will be forwarded to access content for mobile device, desktop device will be forwarded to access specific content
Author: AWS
SpdxLicenseId: Apache-2.0
LicenseUrl: LICENSE.txt
ReadmeUrl: README.md
Labels: ['gcr','gcr-solutions','cloudfront','cloudfront+','aws-cloudfront-extensions','edge','lambda-edge', 'aws']
HomePageUrl: https://www.amazonaws.cn/en/solutions/lambda-edge-collection-for-cloudfront/
SemanticVersion: 1.0.0
SourceCodeUrl: https://github.com/awslabs/aws-cloudfront-extensions/edge/nodejs/serving-based-on-device
Parameters:
DesktopPathParameter:
Type: String
Default: "/desktop"
Description: "Content folder for desktop device"
MobilePathParameter:
Type: String
Default: "/mobile"
Description: "Content folder for mobile device"
TabletPathParameter:
Type: String
Default: "/tablet"
Description: "Content folder for tablet device"
SmartTVPathParameter:
Type: String
Default: "/smarttv"
Description: "Content folder for smart TV"
Resources:
ServingOnDeviceFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: serving-based-on-device/
Handler: app.handler
Runtime: nodejs16.x
Role: !GetAtt EdgeFunctionRole.Arn
EdgeFunctionRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub ${AWS::StackName}-edgeFunction
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
- edgelambda.amazonaws.com
Action: sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
UpdateEdgeCodeFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
DependsOn: ServingOnDeviceFunction
Properties:
CodeUri: 's3://aws-cloudfront-extension-lambda-edge/update-lambda-function.zip'
Handler: index.handler
Runtime: python3.7
Policies:
- Statement:
- Sid: ServingOnDevicePolicy
Effect: Allow
Action:
- lambda:UpdateFunction*
Resource: !GetAtt ServingOnDeviceFunction.Arn
UpdateConfigCustom:
Type: Custom::UpdateConfigCustom
DependsOn: UpdateEdgeCodeFunction
Properties:
ServiceToken: !GetAtt UpdateEdgeCodeFunction.Arn
SourceUrl: 'https://aws-cloudfront-extension-lambda-edge.s3.amazonaws.com/edge/serving-based-on-device/serving-based-on-device.zip'
EdgeFunctionArn: !GetAtt ServingOnDeviceFunction.Arn
HandlerFileName: 'app.js'
PARA_DESKTOP_PATH: !Ref DesktopPathParameter
PARA_MOBILE_PATH: !Ref MobilePathParameter
PARA_TABLET_PATH: !Ref TabletPathParameter
PARA_SMART_TV_PATH: !Ref SmartTVPathParameter
Outputs:
ServingOnDeviceFunction:
Description: "Lambda Edge function ARN"
Value: !GetAtt ServingOnDeviceFunction.Arn
ServingOnDeviceFunctionIamRole:
Description: "Implicit IAM Role created for Simple Lambda Edge function"
Value: !GetAtt EdgeFunctionRole.Arn
SolutionId:
Description: "Solution id"
Value: "SO8101"