-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtemplate-edge.yaml
95 lines (85 loc) · 3.16 KB
/
template-edge.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
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: >
(P13N-RT-APIS-EDGE) - Lambda@Edge functions and related resources for the Personalization APIs solution. Since all Lambda@Edge
functions must be deployed into the us-east-1 region, these resources are packaged separately here so that the primary Personalization
APIs resources can be deployed in a separate region. This stack is only necessary if OAuth2 at the edge is being used.
Parameters:
CognitoRegion:
Type: String
Description: AWS region name where your Cognito user pool is deployed.
AllowedPattern: ^[a-z]{2}-((?:gov|iso|isob)-)?[a-z]+-\d{1}?$
Default: "us-east-1"
CognitoUserPoolId:
Type: String
Description: Amazon Cognito user pool ID for the user pool used to generated JWT tokens for your application.
AllowedPattern: ^[\w-]+$
Globals:
Function:
Tags:
CreatedBy: Personalization-APIs-Solution
Resources:
EdgeAuthFunction:
Type: AWS::Serverless::Function
DeletionPolicy: Retain
UpdateReplacePolicy: Retain
Properties:
Description: Edge function that verifies JWT tokens in CloudFront to maximize caching and reduce latency
Runtime: nodejs18.x
Timeout: 3
CodeUri: src/edge_auth_function
Handler: index.handler
MemorySize: 128 # Restricted by L@E
Role: !GetAtt EdgeAuthExecutionRole.Arn
AutoPublishAlias: Templated
EdgeAuthExecutionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service:
- edgelambda.amazonaws.com
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Path: "/"
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
UpdateEdgeFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/edge_update_function
Handler: main.lambda_handler
Runtime: python3.11
Policies:
- Statement:
- Effect: Allow
Action:
- lambda:GetFunction
- lambda:UpdateFunctionCode
Resource:
- !GetAtt EdgeAuthFunction.Arn
- !Sub "${EdgeAuthFunction.Arn}:Templated"
UpdateEdgeFunctionCustom:
Type: Custom::UpdateConfigCustom
Properties:
ServiceToken: !GetAtt UpdateEdgeFunction.Arn
UserPoolId: !Ref CognitoUserPoolId
CognitoRegion: !Ref CognitoRegion
EdgeFunctionArn: !GetAtt EdgeAuthFunction.Arn
##########################################################################
# Outputs #
##########################################################################
Outputs:
EdgeAuthFunction:
Description: "Edge authentication function ARN"
Value: !GetAtt EdgeAuthFunction.Arn
EdgeAuthFunctionAlias:
Description: Alias for templated version of the Function
Value: !Ref EdgeAuthFunction.Alias
UpdateEdgeFunction:
Description: "Edge function update function ARN"
Value: !GetAtt UpdateEdgeFunction.Arn