Skip to content

Commit

Permalink
Update gucdk to use 53.1.1, update aws-cdk and aws-cdk-lib to use 2.1…
Browse files Browse the repository at this point in the history
…27.0
  • Loading branch information
michaelwmcnamara committed Aug 2, 2024
1 parent e34f261 commit 9380ee0
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 909 deletions.
102 changes: 40 additions & 62 deletions cdk/lib/__snapshots__/generate-product-catalog.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,22 @@ import urllib.request
s3 = boto3.client("s3")
EVENTBRIDGE_CONFIGURATION = 'EventBridgeConfiguration'
CONFIGURATION_TYPES = ["TopicConfigurations", "QueueConfigurations", "LambdaFunctionConfigurations"]
def handler(event: dict, context):
response_status = "SUCCESS"
error_message = ""
try:
props = event["ResourceProperties"]
bucket = props["BucketName"]
notification_configuration = props["NotificationConfiguration"]
request_type = event["RequestType"]
managed = props.get('Managed', 'true').lower() == 'true'
stack_id = event['StackId']
old = event.get("OldResourceProperties", {}).get("NotificationConfiguration", {})
if managed:
config = handle_managed(request_type, notification_configuration)
config = handle_managed(event["RequestType"], notification_configuration)
else:
config = handle_unmanaged(bucket, stack_id, request_type, notification_configuration)
put_bucket_notification_configuration(bucket, config)
config = handle_unmanaged(props["BucketName"], stack_id, event["RequestType"], notification_configuration, old)
s3.put_bucket_notification_configuration(Bucket=props["BucketName"], NotificationConfiguration=config)
except Exception as e:
logging.exception("Failed to put bucket notification configuration")
response_status = "FAILED"
Expand All @@ -65,16 +61,26 @@ def handle_managed(request_type, notification_configuration):
return {}
return notification_configuration
def handle_unmanaged(bucket, stack_id, request_type, notification_configuration):
external_notifications = find_external_notifications(bucket, stack_id)
def handle_unmanaged(bucket, stack_id, request_type, notification_configuration, old):
def with_id(n):
n['Id'] = f"{stack_id}-{hash(json.dumps(n, sort_keys=True))}"
return n
external_notifications = {}
existing_notifications = s3.get_bucket_notification_configuration(Bucket=bucket)
for t in CONFIGURATION_TYPES:
if request_type == 'Update':
ids = [with_id(n) for n in old.get(t, [])]
old_incoming_ids = [n['Id'] for n in ids]
external_notifications[t] = [n for n in existing_notifications.get(t, []) if not n['Id'] in old_incoming_ids]
elif request_type == 'Create':
external_notifications[t] = [n for n in existing_notifications.get(t, [])]
if EVENTBRIDGE_CONFIGURATION in existing_notifications:
external_notifications[EVENTBRIDGE_CONFIGURATION] = existing_notifications[EVENTBRIDGE_CONFIGURATION]
if request_type == 'Delete':
return external_notifications
def with_id(notification):
notification['Id'] = f"{stack_id}-{hash(json.dumps(notification, sort_keys=True))}"
return notification
notifications = {}
for t in CONFIGURATION_TYPES:
external = external_notifications.get(t, [])
Expand All @@ -88,23 +94,6 @@ def handle_unmanaged(bucket, stack_id, request_type, notification_configuration)
return notifications
def find_external_notifications(bucket, stack_id):
existing_notifications = get_bucket_notification_configuration(bucket)
external_notifications = {}
for t in CONFIGURATION_TYPES:
external_notifications[t] = [n for n in existing_notifications.get(t, []) if not n['Id'].startswith(f"{stack_id}-")]
if EVENTBRIDGE_CONFIGURATION in existing_notifications:
external_notifications[EVENTBRIDGE_CONFIGURATION] = existing_notifications[EVENTBRIDGE_CONFIGURATION]
return external_notifications
def get_bucket_notification_configuration(bucket):
return s3.get_bucket_notification_configuration(Bucket=bucket)
def put_bucket_notification_configuration(bucket, notification_configuration):
s3.put_bucket_notification_configuration(Bucket=bucket, NotificationConfiguration=notification_configuration)
def submit_response(event: dict, context, response_status: str, error_message: str):
response_body = json.dumps(
{
Expand Down Expand Up @@ -604,26 +593,22 @@ import urllib.request
s3 = boto3.client("s3")
EVENTBRIDGE_CONFIGURATION = 'EventBridgeConfiguration'
CONFIGURATION_TYPES = ["TopicConfigurations", "QueueConfigurations", "LambdaFunctionConfigurations"]
def handler(event: dict, context):
response_status = "SUCCESS"
error_message = ""
try:
props = event["ResourceProperties"]
bucket = props["BucketName"]
notification_configuration = props["NotificationConfiguration"]
request_type = event["RequestType"]
managed = props.get('Managed', 'true').lower() == 'true'
stack_id = event['StackId']
old = event.get("OldResourceProperties", {}).get("NotificationConfiguration", {})
if managed:
config = handle_managed(request_type, notification_configuration)
config = handle_managed(event["RequestType"], notification_configuration)
else:
config = handle_unmanaged(bucket, stack_id, request_type, notification_configuration)
put_bucket_notification_configuration(bucket, config)
config = handle_unmanaged(props["BucketName"], stack_id, event["RequestType"], notification_configuration, old)
s3.put_bucket_notification_configuration(Bucket=props["BucketName"], NotificationConfiguration=config)
except Exception as e:
logging.exception("Failed to put bucket notification configuration")
response_status = "FAILED"
Expand All @@ -636,16 +621,26 @@ def handle_managed(request_type, notification_configuration):
return {}
return notification_configuration
def handle_unmanaged(bucket, stack_id, request_type, notification_configuration):
external_notifications = find_external_notifications(bucket, stack_id)
def handle_unmanaged(bucket, stack_id, request_type, notification_configuration, old):
def with_id(n):
n['Id'] = f"{stack_id}-{hash(json.dumps(n, sort_keys=True))}"
return n
external_notifications = {}
existing_notifications = s3.get_bucket_notification_configuration(Bucket=bucket)
for t in CONFIGURATION_TYPES:
if request_type == 'Update':
ids = [with_id(n) for n in old.get(t, [])]
old_incoming_ids = [n['Id'] for n in ids]
external_notifications[t] = [n for n in existing_notifications.get(t, []) if not n['Id'] in old_incoming_ids]
elif request_type == 'Create':
external_notifications[t] = [n for n in existing_notifications.get(t, [])]
if EVENTBRIDGE_CONFIGURATION in existing_notifications:
external_notifications[EVENTBRIDGE_CONFIGURATION] = existing_notifications[EVENTBRIDGE_CONFIGURATION]
if request_type == 'Delete':
return external_notifications
def with_id(notification):
notification['Id'] = f"{stack_id}-{hash(json.dumps(notification, sort_keys=True))}"
return notification
notifications = {}
for t in CONFIGURATION_TYPES:
external = external_notifications.get(t, [])
Expand All @@ -659,23 +654,6 @@ def handle_unmanaged(bucket, stack_id, request_type, notification_configuration)
return notifications
def find_external_notifications(bucket, stack_id):
existing_notifications = get_bucket_notification_configuration(bucket)
external_notifications = {}
for t in CONFIGURATION_TYPES:
external_notifications[t] = [n for n in existing_notifications.get(t, []) if not n['Id'].startswith(f"{stack_id}-")]
if EVENTBRIDGE_CONFIGURATION in existing_notifications:
external_notifications[EVENTBRIDGE_CONFIGURATION] = existing_notifications[EVENTBRIDGE_CONFIGURATION]
return external_notifications
def get_bucket_notification_configuration(bucket):
return s3.get_bucket_notification_configuration(Bucket=bucket)
def put_bucket_notification_configuration(bucket, notification_configuration):
s3.put_bucket_notification_configuration(Bucket=bucket, NotificationConfiguration=notification_configuration)
def submit_response(event: dict, context, response_status: str, error_message: str):
response_body = json.dumps(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ exports[`The zuora-salesforce-link-remover stack matches the snapshot 1`] = `
"Arn",
],
},
"","Payload.$":"$"}},"Billing Accounts exist for processing?":{"Type":"Choice","Choices":[{"Variable":"$.billingAccountsToProcess[0]","IsPresent":true,"Next":"Billing Accounts Processor Map"}],"Default":"No Billing Accounts to process"},"No Billing Accounts to process":{"Type":"Pass","End":true},"Billing Accounts Processor Map":{"Type":"Map","ResultPath":"$.billingAccountProcessingAttempts","Next":"Update Salesforce Billing Accounts","Parameters":{"item.$":"$$.Map.Item.Value"},"Iterator":{"StartAt":"Update Zuora Billing Account","States":{"Update Zuora Billing Account":{"End":true,"Retry":[{"ErrorEquals":["Lambda.ClientExecutionTimeoutException","Lambda.ServiceException","Lambda.AWSLambdaException","Lambda.SdkClientException"],"IntervalSeconds":2,"MaxAttempts":6,"BackoffRate":2}],"Type":"Task","OutputPath":"$.Payload","Resource":"arn:",
"","Payload.$":"$"}},"Billing Accounts exist for processing?":{"Type":"Choice","Choices":[{"Variable":"$.billingAccountsToProcess[0]","IsPresent":true,"Next":"Billing Accounts Processor Map"}],"Default":"No Billing Accounts to process"},"No Billing Accounts to process":{"Type":"Pass","End":true},"Billing Accounts Processor Map":{"Type":"Map","ResultPath":"$.billingAccountProcessingAttempts","Next":"Update Salesforce Billing Accounts","Parameters":{"item.$":"$$.Map.Item.Value"},"ItemsPath":"$.billingAccountsToProcess","ItemProcessor":{"ProcessorConfig":{"Mode":"INLINE"},"StartAt":"Update Zuora Billing Account","States":{"Update Zuora Billing Account":{"End":true,"Retry":[{"ErrorEquals":["Lambda.ClientExecutionTimeoutException","Lambda.ServiceException","Lambda.AWSLambdaException","Lambda.SdkClientException"],"IntervalSeconds":2,"MaxAttempts":6,"BackoffRate":2}],"Type":"Task","OutputPath":"$.Payload","Resource":"arn:",
{
"Ref": "AWS::Partition",
},
Expand All @@ -1173,7 +1173,7 @@ exports[`The zuora-salesforce-link-remover stack matches the snapshot 1`] = `
"Arn",
],
},
"","Payload.$":"$"}}}},"ItemsPath":"$.billingAccountsToProcess","MaxConcurrency":10},"Update Salesforce Billing Accounts":{"End":true,"Retry":[{"ErrorEquals":["Lambda.ClientExecutionTimeoutException","Lambda.ServiceException","Lambda.AWSLambdaException","Lambda.SdkClientException"],"IntervalSeconds":2,"MaxAttempts":6,"BackoffRate":2}],"Type":"Task","InputPath":"$.billingAccountProcessingAttempts","OutputPath":"$.Payload","Resource":"arn:",
"","Payload.$":"$"}}}},"MaxConcurrency":10},"Update Salesforce Billing Accounts":{"End":true,"Retry":[{"ErrorEquals":["Lambda.ClientExecutionTimeoutException","Lambda.ServiceException","Lambda.AWSLambdaException","Lambda.SdkClientException"],"IntervalSeconds":2,"MaxAttempts":6,"BackoffRate":2}],"Type":"Task","InputPath":"$.billingAccountProcessingAttempts","OutputPath":"$.Payload","Resource":"arn:",
{
"Ref": "AWS::Partition",
},
Expand Down Expand Up @@ -2577,7 +2577,7 @@ exports[`The zuora-salesforce-link-remover stack matches the snapshot 2`] = `
"Arn",
],
},
"","Payload.$":"$"}},"Billing Accounts exist for processing?":{"Type":"Choice","Choices":[{"Variable":"$.billingAccountsToProcess[0]","IsPresent":true,"Next":"Billing Accounts Processor Map"}],"Default":"No Billing Accounts to process"},"No Billing Accounts to process":{"Type":"Pass","End":true},"Billing Accounts Processor Map":{"Type":"Map","ResultPath":"$.billingAccountProcessingAttempts","Next":"Update Salesforce Billing Accounts","Parameters":{"item.$":"$$.Map.Item.Value"},"Iterator":{"StartAt":"Update Zuora Billing Account","States":{"Update Zuora Billing Account":{"End":true,"Retry":[{"ErrorEquals":["Lambda.ClientExecutionTimeoutException","Lambda.ServiceException","Lambda.AWSLambdaException","Lambda.SdkClientException"],"IntervalSeconds":2,"MaxAttempts":6,"BackoffRate":2}],"Type":"Task","OutputPath":"$.Payload","Resource":"arn:",
"","Payload.$":"$"}},"Billing Accounts exist for processing?":{"Type":"Choice","Choices":[{"Variable":"$.billingAccountsToProcess[0]","IsPresent":true,"Next":"Billing Accounts Processor Map"}],"Default":"No Billing Accounts to process"},"No Billing Accounts to process":{"Type":"Pass","End":true},"Billing Accounts Processor Map":{"Type":"Map","ResultPath":"$.billingAccountProcessingAttempts","Next":"Update Salesforce Billing Accounts","Parameters":{"item.$":"$$.Map.Item.Value"},"ItemsPath":"$.billingAccountsToProcess","ItemProcessor":{"ProcessorConfig":{"Mode":"INLINE"},"StartAt":"Update Zuora Billing Account","States":{"Update Zuora Billing Account":{"End":true,"Retry":[{"ErrorEquals":["Lambda.ClientExecutionTimeoutException","Lambda.ServiceException","Lambda.AWSLambdaException","Lambda.SdkClientException"],"IntervalSeconds":2,"MaxAttempts":6,"BackoffRate":2}],"Type":"Task","OutputPath":"$.Payload","Resource":"arn:",
{
"Ref": "AWS::Partition",
},
Expand All @@ -2588,7 +2588,7 @@ exports[`The zuora-salesforce-link-remover stack matches the snapshot 2`] = `
"Arn",
],
},
"","Payload.$":"$"}}}},"ItemsPath":"$.billingAccountsToProcess","MaxConcurrency":10},"Update Salesforce Billing Accounts":{"End":true,"Retry":[{"ErrorEquals":["Lambda.ClientExecutionTimeoutException","Lambda.ServiceException","Lambda.AWSLambdaException","Lambda.SdkClientException"],"IntervalSeconds":2,"MaxAttempts":6,"BackoffRate":2}],"Type":"Task","InputPath":"$.billingAccountProcessingAttempts","OutputPath":"$.Payload","Resource":"arn:",
"","Payload.$":"$"}}}},"MaxConcurrency":10},"Update Salesforce Billing Accounts":{"End":true,"Retry":[{"ErrorEquals":["Lambda.ClientExecutionTimeoutException","Lambda.ServiceException","Lambda.AWSLambdaException","Lambda.SdkClientException"],"IntervalSeconds":2,"MaxAttempts":6,"BackoffRate":2}],"Type":"Task","InputPath":"$.billingAccountProcessingAttempts","OutputPath":"$.Payload","Resource":"arn:",
{
"Ref": "AWS::Partition",
},
Expand Down
2 changes: 1 addition & 1 deletion cdk/lib/zuora-salesforce-link-remover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export class ZuoraSalesforceLinkRemover extends GuStack {
const billingAccountsProcessingMapDefinition =
updateZuoraBillingAccountLambdaTask;

billingAccountsProcessingMap.iterator(
billingAccountsProcessingMap.itemProcessor(
billingAccountsProcessingMapDefinition,
);

Expand Down
6 changes: 3 additions & 3 deletions cdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
"fix-formatting": "prettier --write **/*.ts"
},
"devDependencies": {
"@guardian/cdk": "52.3.0",
"@guardian/cdk": "53.1.1",
"@types/jest": "^29.5.12",
"@types/node": "^20.11.27",
"aws-cdk": "2.109.0",
"aws-cdk-lib": "2.109.0",
"aws-cdk": "2.133.0",
"aws-cdk-lib": "2.133.0",
"constructs": "10.3.0",
"source-map-support": "^0.5.20",
"ts-node": "^10.9.2"
Expand Down
Loading

0 comments on commit 9380ee0

Please sign in to comment.