@@ -86,6 +86,7 @@ Log Data Event for Troubleshooting
86
86
| [ AppSync Resolver] ( #appsync-resolver ) | ` AppSyncResolverEvent ` |
87
87
| [ AWS Config Rule] ( #aws-config-rule ) | ` AWSConfigRuleEvent ` |
88
88
| [ Bedrock Agent] ( #bedrock-agent ) | ` BedrockAgent ` |
89
+ | [ CloudFormation Custom Resource] ( #cloudformation-custom-resource ) | ` CloudFormationCustomResourceEvent ` |
89
90
| [ CloudWatch Alarm State Change Action] ( #cloudwatch-alarm-state-change-action ) | ` CloudWatchAlarmEvent ` |
90
91
| [ CloudWatch Dashboard Custom Widget] ( #cloudwatch-dashboard-custom-widget ) | ` CloudWatchDashboardCustomWidgetEvent ` |
91
92
| [ CloudWatch Logs] ( #cloudwatch-logs ) | ` CloudWatchLogsEvent ` |
@@ -495,6 +496,54 @@ In this example, we also use the new Logger `correlation_id` and built-in `corre
495
496
--8<-- "examples/event_sources/src/bedrock_agent_event.py"
496
497
```
497
498
499
+ ### CloudFormation Custom Resource
500
+
501
+ === "app.py"
502
+
503
+ ```python
504
+ from aws_lambda_powertools.utilities.data_classes import event_source, CloudFormationCustomResourceEvent
505
+ from aws_lambda_powertools.utilities.data_classes.cloudformation_custom_resource_event import CloudFormationRequestType
506
+ from aws_lambda_powertools.utilities.typing import LambdaContext
507
+ from aws_lambda_powertools import Logger
508
+
509
+ logger = Logger()
510
+
511
+
512
+ @event_source(data_class=CloudFormationCustomResourceEvent)
513
+ def lambda_handler(event: CloudFormationCustomResourceEvent, context: LambdaContext):
514
+ request_type = event.request_type
515
+
516
+ if request_type == CloudFormationRequestType.CREATE:
517
+ return on_create(event)
518
+ if request_type == CloudFormationRequestType.UPDATE:
519
+ return on_update(event)
520
+ if request_type == CloudFormationRequestType.DELETE:
521
+ return on_delete(event)
522
+
523
+
524
+ def on_create(event: CloudFormationCustomResourceEvent):
525
+ props = event.resource_properties
526
+ logger.info(f"Create new resource with props {props}.")
527
+
528
+ # Add your create code here ...
529
+ physical_id = ...
530
+
531
+ return {"PhysicalResourceId": physical_id}
532
+
533
+
534
+ def on_update(event: CloudFormationCustomResourceEvent):
535
+ physical_id = event.physical_resource_id
536
+ props = event.resource_properties
537
+ logger.info(f"Update resource {physical_id} with props {props}.")
538
+ # ...
539
+
540
+
541
+ def on_delete(event: CloudFormationCustomResourceEvent):
542
+ physical_id = event.physical_resource_id
543
+ logger.info(f"Delete resource {physical_id}.")
544
+ # ...
545
+ ```
546
+
498
547
### CloudWatch Dashboard Custom Widget
499
548
500
549
=== "app.py"
0 commit comments