Skip to content

Commit af9be98

Browse files
committed
code changes based on review comments
1 parent 9d4fc63 commit af9be98

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

lambda-cloudwatch-trigger-stack.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ Resources:
118118
add_permission_if_needed(event,context,lambda_arn, log_group_arn, log_group_name)
119119
120120
# Unique filter name for this stack using Lambda ARN
121-
filter_name = f'LambdaSubscription_{hashlib.sha256(lambda_arn.encode()).hexdigest()[:20]}'
121+
filter_name = f'NewRelicLogsLambdaSubscription_{hashlib.sha256(lambda_arn.encode()).hexdigest()[:20]}'
122122
123123
# Retry logic for PutSubscriptionFilter
124124
max_retries = 5
@@ -152,7 +152,7 @@ Resources:
152152
continue
153153
154154
# Unique filter name for this stack using Lambda ARN
155-
filter_name = f'LambdaSubscription_{hashlib.sha256(lambda_arn.encode()).hexdigest()[:20]}'
155+
filter_name = f'NewRelicLogsLambdaSubscription_{hashlib.sha256(lambda_arn.encode()).hexdigest()[:20]}'
156156
157157
158158
#remove the subscription filter

s3-trigger-stack.yaml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,11 @@ Resources:
7878
def lambda_handler(event, context):
7979
response = {}
8080
try:
81+
event_data = event['ResourceProperties']
82+
lambda_arn = event_data.get('LambdaFunctionArn', '')
83+
buckets = event_data.get('S3BucketArns', [])
8184
if event['RequestType'] == 'Delete':
8285
try:
83-
84-
event_data = event['ResourceProperties']
85-
lambda_arn = event_data.get('LambdaFunctionArn', '')
86-
buckets = event_data.get('S3BucketArns', [])
8786
for bucket_arn in buckets:
8887
parts = bucket_arn.split(":::")[-1].split("/", 1)
8988
bucket_name = parts[0]
@@ -92,6 +91,10 @@ Resources:
9291
existing_config = s3.get_bucket_notification_configuration(Bucket=bucket_name)
9392
9493
existing_lambda_configs = existing_config.get('LambdaFunctionConfigurations', [])
94+
if not existing_lambda_configs:
95+
continue
96+
97+
# Deleting the existing configuration
9598
updated_lambda_configs = [config for config in existing_lambda_configs if config['LambdaFunctionArn'] != lambda_arn]
9699
97100
notification_config = {
@@ -104,12 +107,7 @@ Resources:
104107
except Exception as e:
105108
logger.error(f'Delete failed for the bucket triggers with error: {str(e)}')
106109
cfnresponse.send(event, context, cfnresponse.SUCCESS, {})
107-
return {}
108110
else:
109-
event_data = event['ResourceProperties']
110-
111-
lambda_arn = event_data.get('LambdaFunctionArn', '')
112-
buckets = event_data.get('S3BucketArns', [])
113111
bucket_where_trigger_exists = []
114112
for bucket_arn in buckets:
115113

0 commit comments

Comments
 (0)