Skip to content

Commit 305e7cf

Browse files
authored
Merge pull request #123 from SumoLogic/sourabh-aws-observability
Updating Lambda Code.
2 parents 76af3e5 + 39788f9 commit 305e7cf

13 files changed

+659
-604
lines changed

awsautoenableS3Logging/packaged.yaml

+15-42
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ Metadata:
2424
- s3logging
2525
- flowlogs
2626
Name: sumologic-s3-logging-auto-enable
27-
SemanticVersion: 1.0.0
27+
SemanticVersion: 1.0.2
2828
SourceCodeUrl: https://github.com/SumoLogic/sumologic-aws-lambda/tree/master/awsautoenableS3Logging
29-
LicenseUrl: s3://appdevstore/AutoEnableS3Logs/v1.0.0/978602b5b9ec16f8bab0e38fd6b3998f
30-
ReadmeUrl: s3://appdevstore/AutoEnableS3Logs/v1.0.0/d05d411471e0bb4db3389f2523f515f0
29+
LicenseUrl: s3://appdevstore/AutoEnableS3Logs/v1.0.2/978602b5b9ec16f8bab0e38fd6b3998f
30+
ReadmeUrl: s3://appdevstore/AutoEnableS3Logs/v1.0.2/d05d411471e0bb4db3389f2523f515f0
3131
SpdxLicenseId: Apache-2.0
3232
Mappings:
3333
Region2ELBAccountId:
@@ -92,7 +92,7 @@ Parameters:
9292
- S3
9393
- VPC
9494
- ALB
95-
AutoTaggingResourceOptions:
95+
AutoEnableResourceOptions:
9696
Type: String
9797
Description: New - Automatically enables S3 logging for newly created AWS resources
9898
to send logs to S3 Buckets. This does not affect AWS resources already collecting
@@ -129,10 +129,6 @@ Parameters:
129129
Description: True - To remove S3 logging or Vpc flow logs. False - To keep the
130130
S3 logging.
131131
Type: String
132-
ParentStackName:
133-
Type: String
134-
Default: ParentStackName
135-
Description: Parent Stack Name. Do Not Edit the value.
136132
Conditions:
137133
enable_alb_logging:
138134
Fn::And:
@@ -155,25 +151,19 @@ Conditions:
155151
auto_enable_existing:
156152
Fn::Or:
157153
- Fn::Equals:
158-
- Ref: AutoTaggingResourceOptions
154+
- Ref: AutoEnableResourceOptions
159155
- Existing
160156
- Fn::Equals:
161-
- Ref: AutoTaggingResourceOptions
157+
- Ref: AutoEnableResourceOptions
162158
- Both
163159
auto_enable_new:
164160
Fn::Or:
165161
- Fn::Equals:
166-
- Ref: AutoTaggingResourceOptions
162+
- Ref: AutoEnableResourceOptions
167163
- New
168164
- Fn::Equals:
169-
- Ref: AutoTaggingResourceOptions
165+
- Ref: AutoEnableResourceOptions
170166
- Both
171-
do_not_use_parent_stack:
172-
Fn::And:
173-
- Fn::Equals:
174-
- Ref: ParentStackName
175-
- ParentStackName
176-
- Condition: auto_enable_existing
177167
Resources:
178168
SumoLambdaRole:
179169
Type: AWS::IAM::Role
@@ -223,20 +213,7 @@ Resources:
223213
Type: AWS::Serverless::Function
224214
Condition: auto_enable_new
225215
Properties:
226-
FunctionName:
227-
Fn::Join:
228-
- ''
229-
- - sumo-s3-enable-
230-
- Fn::Select:
231-
- 0
232-
- Fn::Split:
233-
- '-'
234-
- Fn::Select:
235-
- 2
236-
- Fn::Split:
237-
- /
238-
- Ref: AWS::StackId
239-
CodeUri: s3://appdevstore/sumo_app_utils/v2.0.0/sumo_app_utils.zip
216+
CodeUri: s3://appdevstore/sumo_app_utils/v2.0.2/sumo_app_utils.zip
240217
Handler: awsresource.enable_s3_logs
241218
Runtime: python3.7
242219
Role:
@@ -404,11 +381,11 @@ Resources:
404381
Id: Main
405382
EnableExisitngAWSResourcesLambda:
406383
Type: AWS::Serverless::Function
407-
Condition: do_not_use_parent_stack
384+
Condition: auto_enable_existing
408385
Properties:
409386
Handler: main.handler
410387
Runtime: python3.7
411-
CodeUri: s3://appdevstore/sumo_app_utils/v2.0.0/sumo_app_utils.zip
388+
CodeUri: s3://appdevstore/sumo_app_utils/v2.0.2/sumo_app_utils.zip
412389
MemorySize: 128
413390
Timeout: 900
414391
Role:
@@ -420,13 +397,9 @@ Resources:
420397
Condition: auto_enable_existing
421398
Properties:
422399
ServiceToken:
423-
Fn::If:
424-
- do_not_use_parent_stack
425-
- Fn::GetAtt:
426-
- EnableExisitngAWSResourcesLambda
427-
- Arn
428-
- Fn::ImportValue:
429-
Fn::Sub: ${ParentStackName}-SumoLogicHelperFunctionARN
400+
Fn::GetAtt:
401+
- EnableExisitngAWSResourcesLambda
402+
- Arn
430403
AWSResource:
431404
Fn::If:
432405
- enable_s3_buckets_logging
@@ -464,4 +437,4 @@ Outputs:
464437
Fn::GetAtt:
465438
- EnableExisitngAWSResourcesLambda
466439
- Arn
467-
Condition: do_not_use_parent_stack
440+
Condition: auto_enable_existing

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

+11-36
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Metadata:
2424
- s3logging
2525
- flowlogs
2626
Name: sumologic-s3-logging-auto-enable
27-
SemanticVersion: 1.0.0
27+
SemanticVersion: 1.0.2
2828
SourceCodeUrl: https://github.com/SumoLogic/sumologic-aws-lambda/tree/master/awsautoenableS3Logging
2929
LicenseUrl: ./LICENSE
3030
ReadmeUrl: ./README.md
@@ -95,7 +95,7 @@ Parameters:
9595
- 'VPC'
9696
- 'ALB'
9797

98-
AutoTaggingResourceOptions:
98+
AutoEnableResourceOptions:
9999
Type: String
100100
Description: "New - Automatically enables S3 logging for newly created AWS resources to send logs to S3 Buckets. This does not affect AWS resources already collecting logs.
101101
Existing - Automatically enables S3 logging for existing AWS resources to send logs to S3 Buckets.
@@ -132,11 +132,6 @@ Parameters:
132132
False - To keep the S3 logging."
133133
Type: String
134134

135-
ParentStackName:
136-
Type: String
137-
Default: "ParentStackName"
138-
Description: Parent Stack Name. Do Not Edit the value.
139-
140135
Conditions:
141136
enable_alb_logging: !And
142137
- !Equals [!Ref AutoEnableLogging, 'ALB']
@@ -149,15 +144,11 @@ Conditions:
149144
- !Condition auto_enable_new
150145

151146
auto_enable_existing: !Or
152-
- !Equals [ !Ref AutoTaggingResourceOptions, 'Existing' ]
153-
- !Equals [ !Ref AutoTaggingResourceOptions, 'Both' ]
147+
- !Equals [ !Ref AutoEnableResourceOptions, 'Existing' ]
148+
- !Equals [ !Ref AutoEnableResourceOptions, 'Both' ]
154149
auto_enable_new: !Or
155-
- !Equals [ !Ref AutoTaggingResourceOptions, 'New' ]
156-
- !Equals [ !Ref AutoTaggingResourceOptions, 'Both' ]
157-
158-
do_not_use_parent_stack: !And
159-
- !Equals [ !Ref ParentStackName, "ParentStackName"]
160-
- !Condition auto_enable_existing
150+
- !Equals [ !Ref AutoEnableResourceOptions, 'New' ]
151+
- !Equals [ !Ref AutoEnableResourceOptions, 'Both' ]
161152

162153
Resources:
163154

@@ -210,17 +201,7 @@ Resources:
210201
Type: 'AWS::Serverless::Function'
211202
Condition: auto_enable_new
212203
Properties:
213-
FunctionName: !Join
214-
- ""
215-
- - "sumo-s3-enable-"
216-
- !Select
217-
- 0
218-
- !Split
219-
- "-"
220-
- !Select
221-
- 2
222-
- !Split ["/", !Ref "AWS::StackId"]
223-
CodeUri: s3://appdevstore/sumo_app_utils/v2.0.0/sumo_app_utils.zip
204+
CodeUri: s3://appdevstore/sumo_app_utils/v2.0.2/sumo_app_utils.zip
224205
Handler: "awsresource.enable_s3_logs"
225206
Runtime: python3.7
226207
Role: !GetAtt SumoLambdaRole.Arn
@@ -354,11 +335,11 @@ Resources:
354335

355336
EnableExisitngAWSResourcesLambda:
356337
Type: 'AWS::Serverless::Function'
357-
Condition: do_not_use_parent_stack
338+
Condition: auto_enable_existing
358339
Properties:
359340
Handler: main.handler
360341
Runtime: python3.7
361-
CodeUri: s3://appdevstore/sumo_app_utils/v2.0.0/sumo_app_utils.zip
342+
CodeUri: s3://appdevstore/sumo_app_utils/v2.0.2/sumo_app_utils.zip
362343
MemorySize: 128
363344
Timeout: 900
364345
Role:
@@ -370,13 +351,7 @@ Resources:
370351
Type: Custom::EnableS3LogsResources
371352
Condition: auto_enable_existing
372353
Properties:
373-
ServiceToken: !If
374-
- do_not_use_parent_stack
375-
- !GetAtt
376-
- EnableExisitngAWSResourcesLambda
377-
- Arn
378-
- !ImportValue
379-
'Fn::Sub': '${ParentStackName}-SumoLogicHelperFunctionARN'
354+
ServiceToken: !GetAtt EnableExisitngAWSResourcesLambda.Arn
380355
AWSResource: !If [enable_s3_buckets_logging, "s3", !If [enable_vpc_flow_logs_logging, "vpc", "elbv2"] ]
381356
BucketName: !Ref BucketName
382357
Filter: !Ref FilterExpression
@@ -395,4 +370,4 @@ Outputs:
395370
EnableExisitngAWSResourcesLambda:
396371
Description: "Lambda Function ARN for Existing AWS Resources"
397372
Value: !GetAtt EnableExisitngAWSResourcesLambda.Arn
398-
Condition: do_not_use_parent_stack
373+
Condition: auto_enable_existing
+29-18
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/bin/sh
22

3-
export AWS_REGION="ap-south-1"
3+
export AWS_REGION="us-east-1"
44
export AWS_PROFILE="personal"
55
# App to test
66
export AppName="tag"
7-
export InstallTypes=("s3" "s3exiting" "vpc" "vpcexisting" "alb" "albexisting")
7+
export InstallTypes=("s3both" "vpcboth" "albboth")
88

99
export BucketName="sumologiclambdahelper-${AWS_REGION}"
1010
export FilterExpression=".*"
@@ -15,41 +15,52 @@ do
1515

1616
if [[ "${InstallType}" == "s3" ]]
1717
then
18-
export EnableLogging="S3"
19-
export TaggingResourceOptions="New"
18+
export AutoEnableLogging="S3"
19+
export AutoEnableResourceOptions="New"
2020
elif [[ "${InstallType}" == "s3exiting" ]]
2121
then
22-
export EnableLogging="S3"
23-
export TaggingResourceOptions="Existing"
22+
export AutoEnableLogging="S3"
23+
export AutoEnableResourceOptions="Existing"
24+
elif [[ "${InstallType}" == "s3both" ]]
25+
then
26+
export AutoEnableLogging="S3"
27+
export AutoEnableResourceOptions="Both"
2428
elif [[ "${InstallType}" == "vpc" ]]
2529
then
26-
export EnableLogging="VPC"
27-
export TaggingResourceOptions="New"
30+
export AutoEnableLogging="VPC"
31+
export AutoEnableResourceOptions="New"
2832
elif [[ "${InstallType}" == "vpcexisting" ]]
2933
then
30-
export EnableLogging="VPC"
31-
export TaggingResourceOptions="Existing"
34+
export AutoEnableLogging="VPC"
35+
export AutoEnableResourceOptions="Existing"
36+
elif [[ "${InstallType}" == "vpcboth" ]]
37+
then
38+
export AutoEnableLogging="VPC"
39+
export AutoEnableResourceOptions="Both"
3240
elif [[ "${InstallType}" == "alb" ]]
3341
then
34-
export EnableLogging="ALB"
35-
export TaggingResourceOptions="New"
42+
export AutoEnableLogging="ALB"
43+
export AutoEnableResourceOptions="New"
3644
elif [[ "${InstallType}" == "albexisting" ]]
3745
then
38-
export EnableLogging="ALB"
39-
export TaggingResourceOptions="Existing"
46+
export AutoEnableLogging="ALB"
47+
export AutoEnableResourceOptions="Existing"
4048
export BucketPrefix=${InstallType}"-LOGS"
49+
elif [[ "${InstallType}" == "albboth" ]]
50+
then
51+
export AutoEnableLogging="ALB"
52+
export AutoEnableResourceOptions="Both"
53+
export BucketPrefix=${InstallType}"-BOTH"
4154
else
4255
echo "No Valid Choice."
4356
fi
4457

4558
# Stack Name
4659
export stackName="${AppName}-${InstallType}"
4760

48-
aws cloudformation deploy --region ${AWS_REGION} --profile ${AWS_PROFILE} --template-file ././../auto_enable_s3_alb.template.yaml \
61+
aws cloudformation deploy --region ${AWS_REGION} --profile ${AWS_PROFILE} --template-file ./../sumologic-s3-logging-auto-enable.yaml \
4962
--capabilities CAPABILITY_IAM CAPABILITY_AUTO_EXPAND CAPABILITY_NAMED_IAM --stack-name "${AppName}-${InstallType}" \
50-
--parameter-overrides EnableLogging="${EnableLogging}" TaggingResourceOptions="${TaggingResourceOptions}" \
63+
--parameter-overrides AutoEnableLogging="${AutoEnableLogging}" AutoEnableResourceOptions="${AutoEnableResourceOptions}" \
5164
FilterExpression="${FilterExpression}" BucketName="${BucketName}" BucketPrefix="${BucketPrefix}" &
5265

53-
export ExistingResource="No"
54-
5566
done

0 commit comments

Comments
 (0)