-
Notifications
You must be signed in to change notification settings - Fork 433
feat(event_source): add CloudFormationCustomResourceEvent data class. #4342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
d90f57b
ec6a6fa
b6a8b7d
da645ba
2f795a5
9fcbe05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# logger.powertools_handler is set with Powertools Logger handler; useful when there are many handlers | ||
LOGGER_ATTRIBUTE_POWERTOOLS_HANDLER = "powertools_handler" | ||
# logger.init attribute is set when Logger has been configured | ||
# logger.init attribute is set when Logger has been configured | ||
LOGGER_ATTRIBUTE_PRECONFIGURED = "init" | ||
LOGGER_ATTRIBUTE_HANDLER = "logger_handler" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from enum import Enum | ||
from typing import Any, Dict, Optional | ||
|
||
from aws_lambda_powertools.utilities.data_classes.common import DictWrapper | ||
|
||
|
||
class CloudFormationRequestType(Enum): | ||
CREATE = "Create" | ||
UPDATE = "Update" | ||
DELETE = "Delete" | ||
|
||
|
||
class CloudFormationCustomResourceEvent(DictWrapper): | ||
@property | ||
def request_type(self) -> CloudFormationRequestType: | ||
return CloudFormationRequestType(self["RequestType"]) | ||
|
||
@property | ||
def service_token(self) -> str: | ||
return self["ServiceToken"] | ||
|
||
@property | ||
def response_url(self) -> str: | ||
return self["ResponseUrl"] | ||
Check warning on line 24 in aws_lambda_powertools/utilities/data_classes/cloudformation_custom_resource_event.py
|
||
|
||
@property | ||
def stack_id(self) -> str: | ||
return self["StackId"] | ||
|
||
@property | ||
def request_id(self) -> str: | ||
return self["RequestId"] | ||
|
||
@property | ||
def logical_resource_id(self) -> str: | ||
return self["LogicalResourceId"] | ||
|
||
@property | ||
def physical_resource_id(self) -> Optional[str]: | ||
leandrodamascena marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return self.get("PhysicalResourceId") | ||
Check warning on line 40 in aws_lambda_powertools/utilities/data_classes/cloudformation_custom_resource_event.py
|
||
leandrodamascena marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@property | ||
def resource_type(self) -> str: | ||
return self["ResourceType"] | ||
|
||
@property | ||
def resource_properties(self) -> Optional[Dict[str, Any]]: | ||
leandrodamascena marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return self.get("ResourceProperties") | ||
leandrodamascena marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@property | ||
def old_resource_properties(self) -> Optional[Dict[str, Any]]: | ||
leandrodamascena marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return self.get("OldResourceProperties") | ||
leandrodamascena marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import pytest | ||
|
||
from aws_lambda_powertools.utilities.data_classes import ( | ||
CloudFormationCustomResourceEvent, | ||
) | ||
from aws_lambda_powertools.utilities.data_classes.cloudformation_custom_resource_event import ( | ||
CloudFormationRequestType, | ||
) | ||
from tests.functional.utils import load_event | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"event_file", | ||
[ | ||
"cloudformationCustomResourceCreate.json", | ||
"cloudformationCustomResourceUpdate.json", | ||
"cloudformationCustomResourceDelete.json", | ||
], | ||
) | ||
def test_cloudformation_custom_resource_event(event_file): | ||
raw_event = load_event(event_file) | ||
parsed_event = CloudFormationCustomResourceEvent(raw_event) | ||
|
||
assert parsed_event.request_type == CloudFormationRequestType(raw_event["RequestType"]) | ||
assert isinstance(parsed_event.request_type, CloudFormationRequestType) | ||
assert parsed_event.service_token == raw_event["ServiceToken"] | ||
assert parsed_event.stack_id == raw_event["StackId"] | ||
assert parsed_event.request_id == raw_event["RequestId"] | ||
assert parsed_event.logical_resource_id == raw_event["LogicalResourceId"] | ||
assert parsed_event.resource_type == raw_event["ResourceType"] | ||
assert parsed_event.resource_properties == raw_event.get("ResourceProperties") | ||
assert parsed_event.old_resource_properties == raw_event.get("OldResourceProperties") |
Uh oh!
There was an error while loading. Please reload this page.