-
Notifications
You must be signed in to change notification settings - Fork 0
/
lambda-template.yml
142 lines (130 loc) · 3.86 KB
/
lambda-template.yml
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
141
142
---
AWSTemplateFormatVersion: 2010-09-09
Description: 'Lambda resources'
Parameters:
NameTag:
Type: String
KmsKeyArn:
Type: String
APISecretPath:
Type: String
AppIds:
Type: String
Resources:
CustomResourceLambdaRole:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: 'sts:AssumeRole'
Principal:
Service: lambda.amazonaws.com
ManagedPolicyArns:
- !Sub 'arn:${AWS::Partition}:iam::aws:policy/AdministratorAccess'
CustomResourceLambda:
Type: 'AWS::Lambda::Function'
Properties:
FunctionName: 'generic-custom-resource-provider'
Handler: generic_provider.lambda_handler
Code: cfn-generic-custom-resource/generic_provider/build
Runtime: python3.7
Role: !Sub '${CustomResourceLambdaRole.Arn}'
Description: 'CloudFormation custom generic resource provider.'
Timeout: 900
Tags:
- Key: Name
Value: !Sub '${NameTag}'
APISecret:
Type: 'Custom::GetSSMSecret'
DependsOn: CustomResourceLambda
Version: 1.0
Properties:
ServiceToken: !Sub 'arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:generic-custom-resource-provider'
NoEcho: True
Version: 1.0
AgentService: ssm
AgentType: client
AgentCreateMethod: get_parameter
AgentWaitQueryExpr: '$.Parameter.Value'
AgentCreateArgs: !Sub |
{
"Name": "${APISecretPath}",
"WithDecryption": true
}
LambdaRole:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- 'lambda.amazonaws.com'
Action:
- 'sts:AssumeRole'
Path: '/'
Policies:
- PolicyName: 'AmazonLambdaServicePolicy'
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- 'logs:CreateLogGroup'
- 'logs:CreateLogStream'
- 'logs:PutLogEvents'
- 'kms:DescribeKey'
- 'kms:Decrypt'
- 'kms:CreateGrant'
Resource: '*'
ManagedPolicyArns:
- !Sub 'arn:${AWS::Partition}:iam::aws:policy/ReadOnlyAccess'
Lambda:
Type: 'AWS::Lambda::Function'
Properties:
Handler: lambda_function.lambda_handler
Code: lambda-functions/call-api
Runtime: python3.7
Role: !Sub '${LambdaRole.Arn}'
Environment:
Variables:
AUTH_TOKEN: !Sub '${APISecret}'
URLS: !Sub 'https://api-${NameTag}.unzoner.com/api/v1.0/devices/purge/${AppIds} https://api-${NameTag}.unzoner.com/api/v1.0/vpnprovider/NordVPN/update https://api-${NameTag}.unzoner.com/api/v1.0/vpnprovider/IPVanish/update'
KmsKeyArn: !Sub '${KmsKeyArn}'
Description: 'Lambda to make API calls.'
Timeout: 900
Tags:
- Key: Name
Value: !Sub '${NameTag}'
LambdaEvent:
Type: 'AWS::Events::Rule'
Properties:
Description: 'Schedule expression to make API calls.'
ScheduleExpression: 'cron(0 10 * * ? *)'
State: 'ENABLED'
Targets:
- Id: Lambda
Arn: !GetAtt Lambda.Arn
LambdaEventPermission:
Type: 'AWS::Lambda::Permission'
Properties:
FunctionName: !Ref 'Lambda'
Action: 'lambda:InvokeFunction'
Principal: 'events.amazonaws.com'
SourceArn: !GetAtt LambdaEvent.Arn
Outputs:
StackName:
Value: !Sub '${AWS::StackName}'
Export:
Name: !Sub 'StackName-${AWS::StackName}'
CustomResourceLambdaArn:
Value: !Sub '${CustomResourceLambda.Arn}'
Export:
Name: !Sub 'CustomResourceLambdaArn-${AWS::StackName}'
Lambda:
Value: !Sub '${Lambda.Arn}'
Export:
Name: !Sub 'Lambda-${AWS::StackName}'