-
Notifications
You must be signed in to change notification settings - Fork 0
/
cf-template.yml
151 lines (150 loc) · 3.94 KB
/
cf-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
143
144
145
146
147
148
149
150
151
AWSTemplateFormatVersion: 2010-09-09
Parameters:
LambdaName:
Type: String
Description: Name of your lambda.
LambdaInterval:
Type: String
Description: Interval of your lambda (in minutes).
S3BucketName:
Type: String
Description: S3 bucket name containing lambda code.
S3CodeArchivePath:
Type: String
Description: Lambda code path inside selected S3 bucket.
AESKey:
Type: String
Description: AES key that code needs to decrypt config file.
NoEcho: true
AESIV:
Type: String
Description: AES IV that code needs, along with AES key, to decrypt config file.
NoEcho: true
ConfigFile:
Type: String
Description: S3 public path to config file.
KMSKeyArn:
Type: String
Description: ARN of KMS key to use for encryption with lambda.
Resources:
IAMRoleInstance:
Type: 'AWS::IAM::Role'
Properties:
RoleName: !Join
- ''
- - !Ref LambdaName
- '-role'
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
Effect: Allow
Action:
- 'sts:AssumeRole'
Principal:
Service:
- lambda.amazonaws.com
Policies:
- PolicyName: root
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- 'logs:CreateLogGroup'
- 'logs:CreateLogStream'
- 'logs:PutLogEvents'
Resource: 'arn:aws:logs:*:*:*'
- Effect: Allow
Action:
- 'ec2:CreateNetworkInterface'
- 'ec2:DeleteNetworkInterface'
- 'ec2:DescribeNetworkInterfaces'
Resource: '*'
- Effect: Allow
Action:
- 'kms:Encrypt'
- 'kms:Decrypt'
Resource: !Ref KMSKeyArn
LambdaInstance:
Type: 'AWS::Lambda::Function'
Properties:
Code:
S3Bucket: !Ref S3BucketName
S3Key: !Ref S3CodeArchivePath
FunctionName: !Ref LambdaName
Description: 'Lambda, created from stack, to check USM sensors status.'
Environment:
Variables:
AES_KEY: !Ref AESKey
AES_IV: !Ref AESIV
CONFIG_FILE: !Ref ConfigFile
Role: !Join
- ''
- - 'arn:aws:iam::'
- !Ref 'AWS::AccountId'
- ':role/'
- !Join
- ''
- - !Ref LambdaName
- '-role'
Handler: script.main
Runtime: python3.6
MemorySize: 128
Timeout: '300'
KmsKeyArn: !Ref KMSKeyArn
DependsOn:
- IAMRoleInstance
CloudWatchEvent:
Type: 'AWS::Events::Rule'
Properties:
Description: !Join
- ''
- - 'Rule for '
- !Ref LambdaName
- ' lambda.'
Name: !Join
- ''
- - !Ref LambdaName
- '-rule'
ScheduleExpression: !Join
- ''
- - 'cron(*/'
- !Ref LambdaInterval
- ' * * * ? *)'
State: ENABLED
Targets:
-
Arn: !GetAtt
- LambdaInstance
- Arn
Id: !Join
- ''
- - 'ruleTarget'
- !Ref LambdaName
DependsOn:
- LambdaInstance
CloudWatchEventPermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Ref LambdaName
Action: lambda:InvokeFunction
Principal: events.amazonaws.com
SourceArn: !GetAtt
- CloudWatchEvent
- Arn
Outputs:
LambdaName:
Description: Name of created AWS Lambda function.
Value: !GetAtt
- LambdaInstance
- Arn
LambdaAttachedRoleName:
Description: Name of attached role to AWS Lambda function.
Value: !GetAtt
- IAMRoleInstance
- Arn
CloudWatchRule:
Description: Name of CloudWatch rule attached to AWS Lambda function.
Value: !GetAtt
- CloudWatchEvent
- Arn