This repository has been archived by the owner on Jul 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy paththundra-lambda-warmup-cloudformation-template.yaml
140 lines (140 loc) · 3.83 KB
/
thundra-lambda-warmup-cloudformation-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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
AWSTemplateFormatVersion: "2010-09-09"
Description: "Thundra Lambda Warmup"
Parameters:
FunctionNameParameter:
Type: String
Default: "thundra-lambda-warmup"
Description: "Name of the 'thundra-lambda-warmup' Lambda function"
TimeoutParameter:
Type: Number
Default: 300
MinValue: 1
MaxValue: 300
Description: "'thundra-lambda-warmup' Lambda function timeout value in seconds."
MemorySizeParameter:
Type: Number
Default: 512
AllowedValues:
- 128
- 192
- 256
- 320
- 384
- 448
- 512
- 576
- 640
- 704
- 768
- 832
- 896
- 960
- 1024
- 1088
- 1152
- 1216
- 1280
- 1344
- 1408
- 1472
- 1536
- 1600
- 1664
- 1728
- 1792
- 1856
- 1920
- 1984
- 2048
- 2112
- 2176
- 2240
- 2304
- 2368
- 2432
- 2496
- 2560
- 2624
- 2688
- 2752
- 2816
- 2880
- 2944
- 3008
Description: "'thundra-lambda-warmup' Lambda function memory size."
Resources:
ThundraLambdaWarmupExecutionRole:
Type: "AWS::IAM::Role"
Properties:
RoleName: !Sub "${FunctionNameParameter}-${AWS::Region}-execution-role"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service: "lambda.amazonaws.com"
Action: "sts:AssumeRole"
Policies:
- PolicyName: !Sub "${FunctionNameParameter}-${AWS::Region}-role"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Action: "logs:CreateLogStream"
Resource: !Sub "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/${FunctionNameParameter}:*"
- Effect: "Allow"
Action: "logs:PutLogEvents"
Resource: !Sub "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/${FunctionNameParameter}:*:*"
- Effect: "Allow"
Action: "lambda:ListFunctions"
Resource: "*"
- Effect: "Allow"
Action: [ "lambda:InvokeFunction", "lambda:ListAliases" ]
Resource: !Sub "arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:*"
ThundraLambdaWarmupLogGroup:
Type: "AWS::Logs::LogGroup"
Properties:
LogGroupName: !Sub "/aws/lambda/${FunctionNameParameter}"
ThundraLambdaWarmupFunction:
Type: "AWS::Lambda::Function"
Properties:
FunctionName:
Ref: FunctionNameParameter
Handler: "io.thundra.lambda.warmup.WarmupHandler"
Description: "Thundra Lambda Warmup"
Role: !GetAtt [ ThundraLambdaWarmupExecutionRole, Arn ]
Code:
S3Bucket: !Sub "thundra-dist-${AWS::Region}"
S3Key: "thundra-lambda-warmup.jar"
Runtime: java8.al2
Timeout:
Ref: TimeoutParameter
MemorySize:
Ref: MemorySizeParameter
DependsOn: [ThundraLambdaWarmupExecutionRole, ThundraLambdaWarmupLogGroup]
ThundraLambdaWarmupSchedule:
Type: "AWS::Events::Rule"
Properties:
ScheduleExpression: "rate(5 minutes)"
State: "ENABLED"
Name: !Sub "${FunctionNameParameter}-schedule"
Targets:
-
Arn:
Fn::GetAtt:
- "ThundraLambdaWarmupFunction"
- "Arn"
Id: !Sub "${FunctionNameParameter}-schedule"
ThundraLambdaWarmupSchedulePermission:
Type: "AWS::Lambda::Permission"
Properties:
FunctionName:
Fn::GetAtt:
- "ThundraLambdaWarmupFunction"
- "Arn"
Action: "lambda:InvokeFunction"
Principal: "events.amazonaws.com"
SourceArn:
Fn::GetAtt:
- "ThundraLambdaWarmupSchedule"
- "Arn"