@@ -78,12 +78,11 @@ Resources:
78
78
def lambda_handler(event, context):
79
79
response = {}
80
80
try:
81
+ event_data = event['ResourceProperties']
82
+ lambda_arn = event_data.get('LambdaFunctionArn', '')
83
+ buckets = event_data.get('S3BucketArns', [])
81
84
if event['RequestType'] == 'Delete':
82
85
try:
83
-
84
- event_data = event['ResourceProperties']
85
- lambda_arn = event_data.get('LambdaFunctionArn', '')
86
- buckets = event_data.get('S3BucketArns', [])
87
86
for bucket_arn in buckets:
88
87
parts = bucket_arn.split(":::")[-1].split("/", 1)
89
88
bucket_name = parts[0]
@@ -92,6 +91,10 @@ Resources:
92
91
existing_config = s3.get_bucket_notification_configuration(Bucket=bucket_name)
93
92
94
93
existing_lambda_configs = existing_config.get('LambdaFunctionConfigurations', [])
94
+ if not existing_lambda_configs:
95
+ continue
96
+
97
+ # Deleting the existing configuration
95
98
updated_lambda_configs = [config for config in existing_lambda_configs if config['LambdaFunctionArn'] != lambda_arn]
96
99
97
100
notification_config = {
@@ -104,12 +107,7 @@ Resources:
104
107
except Exception as e :
105
108
logger.error(f'Delete failed for the bucket triggers with error : {str(e)}')
106
109
cfnresponse.send(event, context, cfnresponse.SUCCESS, {})
107
- return {}
108
110
else :
109
- event_data = event['ResourceProperties']
110
-
111
- lambda_arn = event_data.get('LambdaFunctionArn', '')
112
- buckets = event_data.get('S3BucketArns', [])
113
111
bucket_where_trigger_exists = []
114
112
for bucket_arn in buckets :
115
113
0 commit comments