-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rollover.yaml
93 lines (89 loc) · 2.38 KB
/
Rollover.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
AWSTemplateFormatVersion: '2010-09-09'
Description: Configure ES Log rollover
Parameters:
S3BucketName:
Type: String
Default: 'lambda-code'
Description: Lambda Code zip file S3 bucket name
S3FileName:
Type: String
Default: 'rollover.zip'
Description: Lambda Code zip filename in S3
ESClusterDomainEP:
Type: String
Description: ES Cluster Domain Endpoint
EnvironmentName:
Type: String
Default: 'development'
Description: Environment Name
CronExpression:
Type: String
Default: '0 0 * * ? *'
Description: Cron Expression for the rule
LabmdaRoleArn:
Type: String
Description: Lambda Role Arn
MemorySizeMB:
Type: Number
Default: 1024
Description: Lambda max MemorySize in MB
LambdaTimeoutSeconds:
Type: Number
Default: 900
Description: Lambda timeout value
Metadata:
'AWS::CloudFormation::Interface':
ParameterGroups:
- Label:
default: Configurations
Parameters:
- S3BucketName
- S3FileName
- CronExpression
- LabmdaRoleArn
- ESClusterDomainEP
- EnvironmentName
- MemorySizeMB
- LambdaTimeoutSeconds
Resources:
LogsRollover:
Type: 'AWS::Lambda::Function'
Properties:
Runtime: nodejs12.x
Role: !Ref LabmdaRoleArn
Handler: index.handler
Environment:
Variables:
elasticsearch_cluster_dns: !Ref ESClusterDomainEP
environment_name: !Ref EnvironmentName
MemorySize: !Ref MemorySizeMB
Timeout: !Ref LambdaTimeoutSeconds
Code:
S3Bucket: !Sub ${S3BucketName}
S3Key: !Sub ${S3FileName}
Description: Invoke a function during stack creation.
CloudWatchSubscriptionFunctionPermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName:
Fn::GetAtt:
- "LogsRollover"
- "Arn"
Action: 'lambda:InvokeFunction'
Principal: 'events.amazonaws.com'
SourceArn:
Fn::GetAtt:
- "CloudWatchLogRolloverRule"
- "Arn"
CloudWatchLogRolloverRule:
Type: 'AWS::Events::Rule'
Properties:
Description: 'Rollover Log indices'
ScheduleExpression: !Sub 'cron(${CronExpression})'
State: 'ENABLED'
Targets:
- Id: 'Rollover-logs-daily'
Arn:
Fn::GetAtt:
- "LogsRollover"
- "Arn"