-
Notifications
You must be signed in to change notification settings - Fork 0
/
LogsToES.yaml
87 lines (85 loc) · 2.52 KB
/
LogsToES.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
AWSTemplateFormatVersion: 2010-09-09
Description: Create Log publish resources
Parameters:
EnvironmentName:
Type: String
Default: 'development'
Description: Name Of The Environment
ESClusterDomainEP:
Type: String
Description: ES Cluster Domain Endpoint
ClusterName:
Type: String
Default: 'dev-eks'
Description: Name Of The EKS Cluster
S3BucketName:
Type: String
Default: 'lambda-code'
Description: Lambda Code zip file S3 bucket name
MemorySizeMB:
Type: Number
Default: 256
Description: Lambda max MemorySize in MB
LambdaTimeoutSeconds:
Type: Number
Default: 30
Description: Lambda timeout value
S3FileName:
Type: String
Default: 'logstoes-development.zip'
Description: Lambda Code zip filename in S3
LabmdaRoleArn:
Type: String
Description: Lambda Role Arn
Metadata:
'AWS::CloudFormation::Interface':
ParameterGroups:
- Label:
default: Configurations
Parameters:
- EnvironmentName
- ESClusterDomainEP
- ClusterName
- S3BucketName
- S3FileName
- LabmdaRoleArn
- MemorySizeMB
- LambdaTimeoutSeconds
Resources:
LogsToElasticsearch:
Type: 'AWS::Lambda::Function'
Properties:
FunctionName: !Sub 'LogsToElasticsearch-${EnvironmentName}-${ClusterName}'
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:
- "LogsToElasticsearch"
- "Arn"
Action: 'lambda:InvokeFunction'
Principal: !Sub 'logs.${AWS::Region}.amazonaws.com'
SourceArn: !Sub 'arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/${EnvironmentName}/eks/${ClusterName}/containers:*'
SubscriptionFilter:
Type: AWS::Logs::SubscriptionFilter
DependsOn: CloudWatchSubscriptionFunctionPermission
Properties:
LogGroupName: !Sub '/${EnvironmentName}/eks/${ClusterName}/containers'
FilterPattern: ""
DestinationArn:
Fn::GetAtt:
- "LogsToElasticsearch"
- "Arn"