Skip to content

Commit 5182c9d

Browse files
authored
Merge pull request #145 from SumoLogic/ELBClassicAutoEnable
Enabling Auto Enable feature for ELB classic from AWSO
2 parents 3d723a6 + a5af6e5 commit 5182c9d

File tree

3 files changed

+289
-34
lines changed

3 files changed

+289
-34
lines changed

awsautoenableS3Logging/packaged.yaml

Lines changed: 73 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
AWSTemplateFormatVersion: '2010-09-09'
22
Transform: AWS::Serverless-2016-10-31
33
Description: Lambda Function for auto enable s3 logs for S3 Buckets, VPCs, Subnets,
4-
Network Interfaces and Application load balancer.
4+
Network Interfaces, Application load balancer and Classic load balancer
55
Globals:
66
Function:
77
Timeout: 300
@@ -24,35 +24,35 @@ Metadata:
2424
- s3logging
2525
- flowlogs
2626
Name: sumologic-s3-logging-auto-enable
27-
SemanticVersion: 1.0.2
27+
SemanticVersion: 1.0.3
2828
SourceCodeUrl: https://github.com/SumoLogic/sumologic-aws-lambda/tree/master/awsautoenableS3Logging
29-
LicenseUrl: s3://appdevstore/AutoEnableS3Logs/v1.0.2/978602b5b9ec16f8bab0e38fd6b3998f
30-
ReadmeUrl: s3://appdevstore/AutoEnableS3Logs/v1.0.2/d05d411471e0bb4db3389f2523f515f0
29+
LicenseUrl: s3://appdevstore/AutoEnableS3Logs/v1.0.3/978602b5b9ec16f8bab0e38fd6b3998f
30+
ReadmeUrl: s3://appdevstore/AutoEnableS3Logs/v1.0.3/d05d411471e0bb4db3389f2523f515f0
3131
SpdxLicenseId: Apache-2.0
3232
Mappings:
3333
Region2ELBAccountId:
3434
us-east-1:
3535
AccountId: '127311923021'
3636
us-east-2:
37-
AccountId: 033677994240
37+
AccountId: '033677994240'
3838
us-west-1:
39-
AccountId: 027434742980
39+
AccountId: '027434742980'
4040
us-west-2:
4141
AccountId: '797873946194'
4242
af-south-1:
43-
AccountId: 098369216593
43+
AccountId: '098369216593'
4444
ca-central-1:
4545
AccountId: '985666609251'
4646
eu-central-1:
47-
AccountId: 054676820928
47+
AccountId: '054676820928'
4848
eu-west-1:
4949
AccountId: '156460612806'
5050
eu-west-2:
5151
AccountId: '652711504416'
5252
eu-south-1:
5353
AccountId: '635631232127'
5454
eu-west-3:
55-
AccountId: 009996457667
55+
AccountId: '009996457667'
5656
eu-north-1:
5757
AccountId: '897822967062'
5858
ap-east-1:
@@ -74,7 +74,7 @@ Mappings:
7474
sa-east-1:
7575
AccountId: '507241528517'
7676
us-gov-west-1:
77-
AccountId: 048591011584
77+
AccountId: '048591011584'
7878
us-gov-east-1:
7979
AccountId: '190560391635'
8080
cn-north-1:
@@ -86,12 +86,14 @@ Parameters:
8686
Type: String
8787
Description: S3 - To Enable S3 Audit Logging for new S3 buckets. VPC - To Enable
8888
VPC flow logs for new VPC, Subnets and Network Interfaces. ALB - To Enable S3
89-
Logging for new Application Load Balancer.
89+
Logging for new Application Load Balancer. ELB - To Enable S3 logging for new
90+
Classic Load Balancer
9091
AllowedPattern: .+
9192
AllowedValues:
9293
- S3
9394
- VPC
9495
- ALB
96+
- ELB
9597
AutoEnableResourceOptions:
9698
Type: String
9799
Description: New - Automatically enables S3 logging for newly created AWS resources
@@ -136,6 +138,12 @@ Conditions:
136138
- Ref: AutoEnableLogging
137139
- ALB
138140
- Condition: auto_enable_new
141+
enable_elb_logging:
142+
Fn::And:
143+
- Fn::Equals:
144+
- Ref: AutoEnableLogging
145+
- ELB
146+
- Condition: auto_enable_new
139147
enable_s3_buckets_logging:
140148
Fn::And:
141149
- Fn::Equals:
@@ -213,7 +221,7 @@ Resources:
213221
Type: AWS::Serverless::Function
214222
Condition: auto_enable_new
215223
Properties:
216-
CodeUri: s3://appdevstore/sumo_app_utils/v2.0.2/sumo_app_utils.zip
224+
CodeUri: s3://appdevstore/sumo_app_utils/v2.0.8/sumo_app_utils.zip
217225
Handler: awsresource.enable_s3_logs
218226
Runtime: python3.7
219227
Role:
@@ -379,13 +387,61 @@ Resources:
379387
- EnableNewAWSResourcesLambda
380388
- Arn
381389
Id: Main
390+
AutoEnableElbLogEventsInvokePermission:
391+
Type: AWS::Lambda::Permission
392+
Condition: enable_elb_logging
393+
Properties:
394+
Action: lambda:InvokeFunction
395+
FunctionName:
396+
Ref: EnableNewAWSResourcesLambda
397+
Principal: events.amazonaws.com
398+
SourceArn:
399+
Fn::GetAtt:
400+
- AutoEnableElbLogEventsRuleTrigger
401+
- Arn
402+
AutoEnableElbLogEventsRuleTrigger:
403+
Type: AWS::Events::Rule
404+
Condition: enable_elb_logging
405+
Properties:
406+
Description: Auto-Enable S3 logging for ELB classic resources with Lambda from
407+
events
408+
EventPattern:
409+
source:
410+
- aws.elasticloadbalancing
411+
detail-type:
412+
- AWS API Call via CloudTrail
413+
detail:
414+
eventSource:
415+
- elasticloadbalancing.amazonaws.com
416+
eventName:
417+
- CreateLoadBalancer
418+
Name:
419+
Fn::Join:
420+
- ''
421+
- - sumo-logic-elb-s3-
422+
- Fn::Select:
423+
- 0
424+
- Fn::Split:
425+
- '-'
426+
- Fn::Select:
427+
- 2
428+
- Fn::Split:
429+
- /
430+
- Ref: AWS::StackId
431+
State: ENABLED
432+
Targets:
433+
- Arn:
434+
Fn::GetAtt:
435+
- EnableNewAWSResourcesLambda
436+
- Arn
437+
Id: Main
382438
EnableExisitngAWSResourcesLambda:
383439
Type: AWS::Serverless::Function
384440
Condition: auto_enable_existing
385441
Properties:
386442
Handler: main.handler
387443
Runtime: python3.7
388-
CodeUri: s3://appdevstore/sumo_app_utils/v2.0.2/sumo_app_utils.zip
444+
CodeUri: s3://appdevstore/sumo_app_utils/v2.0.8/sumo_app_utils.zip
389445
MemorySize: 128
390446
Timeout: 900
391447
Role:
@@ -407,7 +463,10 @@ Resources:
407463
- Fn::If:
408464
- enable_vpc_flow_logs_logging
409465
- vpc
410-
- elbv2
466+
- Fn::If:
467+
- enable_alb_logging
468+
- elbv2
469+
- elb
411470
BucketName:
412471
Ref: BucketName
413472
Filter:

awsautoenableS3Logging/sumologic-s3-logging-auto-enable.yaml

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
AWSTemplateFormatVersion: '2010-09-09'
22
Transform: AWS::Serverless-2016-10-31
3-
Description: "Lambda Function for auto enable s3 logs for S3 Buckets, VPCs, Subnets, Network Interfaces and Application load balancer."
3+
Description: "Lambda Function for auto enable s3 logs for S3 Buckets, VPCs, Subnets, Network Interfaces, Application load balancer and Classic load balancer"
44

55
Globals:
66
Function:
@@ -24,7 +24,7 @@ Metadata:
2424
- s3logging
2525
- flowlogs
2626
Name: sumologic-s3-logging-auto-enable
27-
SemanticVersion: 1.0.2
27+
SemanticVersion: 1.0.3
2828
SourceCodeUrl: https://github.com/SumoLogic/sumologic-aws-lambda/tree/master/awsautoenableS3Logging
2929
LicenseUrl: ./LICENSE
3030
ReadmeUrl: ./README.md
@@ -88,12 +88,14 @@ Parameters:
8888
Type: String
8989
Description: "S3 - To Enable S3 Audit Logging for new S3 buckets.
9090
VPC - To Enable VPC flow logs for new VPC, Subnets and Network Interfaces.
91-
ALB - To Enable S3 Logging for new Application Load Balancer."
91+
ALB - To Enable S3 Logging for new Application Load Balancer.
92+
ELB - To Enable S3 logging for new Classic Load Balancer"
9293
AllowedPattern: ".+"
9394
AllowedValues:
9495
- 'S3'
9596
- 'VPC'
9697
- 'ALB'
98+
- 'ELB'
9799

98100
AutoEnableResourceOptions:
99101
Type: String
@@ -126,7 +128,7 @@ Parameters:
126128
RemoveOnDeleteStack:
127129
AllowedValues:
128130
- true
129-
- false
131+
- false
130132
Default: true
131133
Description: "True - To remove S3 logging or Vpc flow logs.
132134
False - To keep the S3 logging."
@@ -136,6 +138,9 @@ Conditions:
136138
enable_alb_logging: !And
137139
- !Equals [!Ref AutoEnableLogging, 'ALB']
138140
- !Condition auto_enable_new
141+
enable_elb_logging: !And
142+
- !Equals [!Ref AutoEnableLogging, 'ELB']
143+
- !Condition auto_enable_new
139144
enable_s3_buckets_logging: !And
140145
- !Equals [!Ref AutoEnableLogging, 'S3']
141146
- !Condition auto_enable_new
@@ -201,7 +206,7 @@ Resources:
201206
Type: 'AWS::Serverless::Function'
202207
Condition: auto_enable_new
203208
Properties:
204-
CodeUri: s3://appdevstore/sumo_app_utils/v2.0.2/sumo_app_utils.zip
209+
CodeUri: s3://appdevstore/sumo_app_utils/v2.0.8/sumo_app_utils.zip
205210
Handler: "awsresource.enable_s3_logs"
206211
Runtime: python3.7
207212
Role: !GetAtt SumoLambdaRole.Arn
@@ -333,13 +338,52 @@ Resources:
333338
- Arn: !GetAtt EnableNewAWSResourcesLambda.Arn
334339
Id: Main
335340

341+
AutoEnableElbLogEventsInvokePermission:
342+
Type: AWS::Lambda::Permission
343+
Condition: enable_elb_logging
344+
Properties:
345+
Action: lambda:InvokeFunction
346+
FunctionName: !Ref EnableNewAWSResourcesLambda
347+
Principal: "events.amazonaws.com"
348+
SourceArn: !GetAtt AutoEnableElbLogEventsRuleTrigger.Arn
349+
350+
AutoEnableElbLogEventsRuleTrigger:
351+
Type: 'AWS::Events::Rule'
352+
Condition: enable_elb_logging
353+
Properties:
354+
Description: Auto-Enable S3 logging for ELB classic resources with Lambda from events
355+
EventPattern:
356+
source:
357+
- aws.elasticloadbalancing
358+
detail-type:
359+
- AWS API Call via CloudTrail
360+
detail:
361+
eventSource:
362+
- elasticloadbalancing.amazonaws.com
363+
eventName:
364+
- CreateLoadBalancer
365+
Name: !Join
366+
- ""
367+
- - "sumo-logic-elb-s3-"
368+
- !Select
369+
- 0
370+
- !Split
371+
- "-"
372+
- !Select
373+
- 2
374+
- !Split ["/", !Ref "AWS::StackId"]
375+
State: ENABLED
376+
Targets:
377+
- Arn: !GetAtt EnableNewAWSResourcesLambda.Arn
378+
Id: Main
379+
336380
EnableExisitngAWSResourcesLambda:
337381
Type: 'AWS::Serverless::Function'
338382
Condition: auto_enable_existing
339383
Properties:
340384
Handler: main.handler
341385
Runtime: python3.7
342-
CodeUri: s3://appdevstore/sumo_app_utils/v2.0.2/sumo_app_utils.zip
386+
CodeUri: s3://appdevstore/sumo_app_utils/v2.0.8/sumo_app_utils.zip
343387
MemorySize: 128
344388
Timeout: 900
345389
Role:
@@ -352,7 +396,7 @@ Resources:
352396
Condition: auto_enable_existing
353397
Properties:
354398
ServiceToken: !GetAtt EnableExisitngAWSResourcesLambda.Arn
355-
AWSResource: !If [enable_s3_buckets_logging, "s3", !If [enable_vpc_flow_logs_logging, "vpc", "elbv2"] ]
399+
AWSResource: !If [enable_s3_buckets_logging, "s3", !If [enable_vpc_flow_logs_logging, "vpc", !If [enable_alb_logging, "elbv2","elb"]] ]
356400
BucketName: !Ref BucketName
357401
Filter: !Ref FilterExpression
358402
BucketPrefix: !Ref BucketPrefix

0 commit comments

Comments
 (0)