From cb61bce4643cf6e3785ffaf06fbd036d38f06bfc Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Thu, 27 Apr 2023 17:05:31 +0100 Subject: [PATCH 01/14] feat(dataclass): adding dataclass events --- .../utilities/data_classes/__init__.py | 2 + .../utilities/data_classes/aws_config.py | 241 ++++++++++++++++++ 2 files changed, 243 insertions(+) create mode 100644 aws_lambda_powertools/utilities/data_classes/aws_config.py diff --git a/aws_lambda_powertools/utilities/data_classes/__init__.py b/aws_lambda_powertools/utilities/data_classes/__init__.py index 1d268fef7cb..a0df972a0cb 100644 --- a/aws_lambda_powertools/utilities/data_classes/__init__.py +++ b/aws_lambda_powertools/utilities/data_classes/__init__.py @@ -5,6 +5,7 @@ from .alb_event import ALBEvent from .api_gateway_proxy_event import APIGatewayProxyEvent, APIGatewayProxyEventV2 from .appsync_resolver_event import AppSyncResolverEvent +from .aws_config import AWSConfigEvent from .cloud_watch_custom_widget_event import CloudWatchDashboardCustomWidgetEvent from .cloud_watch_logs_event import CloudWatchLogsEvent from .code_pipeline_job_event import CodePipelineJobEvent @@ -42,4 +43,5 @@ "SNSEvent", "SQSEvent", "event_source", + "AWSConfigEvent", ] diff --git a/aws_lambda_powertools/utilities/data_classes/aws_config.py b/aws_lambda_powertools/utilities/data_classes/aws_config.py new file mode 100644 index 00000000000..ee40cdbf98f --- /dev/null +++ b/aws_lambda_powertools/utilities/data_classes/aws_config.py @@ -0,0 +1,241 @@ +from __future__ import annotations + +import json +from typing import Dict, List + +from aws_lambda_powertools.utilities.data_classes.common import DictWrapper + + +def get_invoke_event(invoking_event: dict) -> AWSConfigConfigurationChanged | AWSConfigScheduledNotification: + message_type = invoking_event.get("messageType") + + if message_type == "ConfigurationItemChangeNotification": + return AWSConfigConfigurationItemChanged(invoking_event) + + if message_type == "ScheduledNotification": + return AWSConfigScheduledNotification(invoking_event) + + if message_type == "OversizedConfigurationItemChangeNotification": + return AWSConfigOversizedConfiguration(invoking_event) + + +class AWSConfigConfigurationItemChanged(DictWrapper): + @property + def related_events(self) -> List: + """The version of the event.""" + return self["relatedEvents"] + + @property + def relationships(self) -> List: + """The version of the event.""" + return self["relationships"] + + @property + def configuration(self) -> Dict: + """The version of the event.""" + return self["configuration"] + + @property + def supplementary_configuration(self) -> Dict: + """The version of the event.""" + return self["supplementaryConfiguration"] + + @property + def tags(self) -> Dict: + """The version of the event.""" + return self["tags"] + + @property + def configuration_item_version(self) -> str: + """The version of the event.""" + return self["configurationItemVersion"] + + @property + def configuration_item_capture_time(self) -> str: + """The version of the event.""" + return self["configurationItemCaptureTime"] + + @property + def configuration_state_id(self) -> str: + """The version of the event.""" + return self["configurationStateId"] + + @property + def accountid(self) -> str: + """The version of the event.""" + return self["awsAccountId"] + + @property + def configuration_item_status(self) -> str: + """The version of the event.""" + return self["configurationItemStatus"] + + @property + def resource_type(self) -> str: + """The version of the event.""" + return self["resourceType"] + + @property + def resource_id(self) -> str: + """The version of the event.""" + return self["resourceId"] + + @property + def resource_name(self) -> str: + """The version of the event.""" + return self["resourceName"] + + @property + def resource_arn(self) -> str: + """The version of the event.""" + return self["ARN"] + + @property + def region(self) -> str: + """The version of the event.""" + return self["awsRegion"] + + @property + def availability_zone(self) -> str: + """The version of the event.""" + return self["availabilityZone"] + + @property + def configuration_state_md5_hash(self) -> str: + """The version of the event.""" + return self["configurationStateMd5Hash"] + + @property + def resource_creation_time(self) -> str: + """The version of the event.""" + return self["resourceCreationTime"] + + +class AWSConfigConfigurationChanged(DictWrapper): + @property + def configuration_item_diff(self) -> Dict: + """The version of the event.""" + return self["configurationItemDiff"] + + @property + def configuration_item(self) -> AWSConfigConfigurationItemChanged: + """The version of the event.""" + return AWSConfigConfigurationItemChanged(self["configurationItem"]) + + def raw_configuration_item(self) -> Dict: + """The version of the event.""" + return self["configurationItem"] + + @property + def record_version(self) -> str: + """The version of the event.""" + return self["recordVersion"] + + @property + def message_type(self) -> str: + """The version of the event.""" + return self["messageType"] + + @property + def notification_creation_time(self) -> str: + """The version of the event.""" + return self["notificationCreationTime"] + + +class AWSConfigScheduledNotification(DictWrapper): + @property + def accountid(self) -> str: + """The version of the event.""" + return self["awsAccountId"] + + @property + def notification_creation_time(self) -> str: + """The version of the event.""" + return self["notificationCreationTime"] + + @property + def record_version(self) -> str: + """The version of the event.""" + return self["recordVersion"] + + @property + def message_type(self) -> str: + """The version of the event.""" + return self["messageType"] + + +class AWSConfigOversizedConfiguration(DictWrapper): + @property + def accountid(self) -> str: + """The version of the event.""" + return self["awsAccountId"] + + +class AWSConfigEvent(DictWrapper): + """Events for AWS Config Rules + Documentation: + -------------- + - https://docs.aws.amazon.com/config/latest/developerguide/evaluate-config_develop-rules_lambda-functions.html + """ + + @property + def version(self) -> str: + """The version of the event.""" + return self["version"] + + @property + def invoking_event( + self, + ) -> AWSConfigConfigurationChanged | AWSConfigScheduledNotification | AWSConfigOversizedConfiguration: + """The version of the event.""" + return get_invoke_event(json.loads(self["invokingEvent"])) + + @property + def raw_invoking_event(self) -> str: + """The version of the event.""" + return self["invokingEvent"] + + @property + def rule_parameters(self) -> Dict: + """The parameters of the event.""" + return json.loads(self["ruleParameters"]) + + @property + def result_token(self) -> str: + """The token of the event.""" + return self["resultToken"] + + @property + def event_left_scope(self) -> bool: + """The left scope of the event.""" + return self["eventLeftScope"] + + @property + def execution_role_arn(self) -> str: + """The execution role arn of the event.""" + return self["executionRoleArn"] + + @property + def config_rule_arn(self) -> str: + """The arn of the rule of the event.""" + return self["configRuleArn"] + + @property + def config_rule_name(self) -> str: + """The name of the rule of the event.""" + return self["configRuleArn"] + + @property + def config_rule_id(self) -> str: + """The id of the rule of the event.""" + return self["configRuleId"] + + @property + def accountid(self) -> str: + """The accountid of the event.""" + return self["accountId"] + + @property + def evalution_mode(self) -> str: + """The evalution mode of the event.""" + return self["evaluationMode"] From 0b88d332a9f850a97ea99372308d71b38c3d0a86 Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Thu, 27 Apr 2023 17:14:33 +0100 Subject: [PATCH 02/14] feat(dataclass): adding dataclass events --- .../utilities/data_classes/aws_config.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/aws_lambda_powertools/utilities/data_classes/aws_config.py b/aws_lambda_powertools/utilities/data_classes/aws_config.py index ee40cdbf98f..4da033315bf 100644 --- a/aws_lambda_powertools/utilities/data_classes/aws_config.py +++ b/aws_lambda_powertools/utilities/data_classes/aws_config.py @@ -6,11 +6,13 @@ from aws_lambda_powertools.utilities.data_classes.common import DictWrapper -def get_invoke_event(invoking_event: dict) -> AWSConfigConfigurationChanged | AWSConfigScheduledNotification: +def get_invoke_event( + invoking_event: dict, +) -> AWSConfigConfigurationChanged | AWSConfigScheduledNotification | AWSConfigOversizedConfiguration | None: message_type = invoking_event.get("messageType") if message_type == "ConfigurationItemChangeNotification": - return AWSConfigConfigurationItemChanged(invoking_event) + return AWSConfigConfigurationChanged(invoking_event) if message_type == "ScheduledNotification": return AWSConfigScheduledNotification(invoking_event) @@ -18,6 +20,9 @@ def get_invoke_event(invoking_event: dict) -> AWSConfigConfigurationChanged | AW if message_type == "OversizedConfigurationItemChangeNotification": return AWSConfigOversizedConfiguration(invoking_event) + # In case of a unknown event + return None + class AWSConfigConfigurationItemChanged(DictWrapper): @property @@ -186,7 +191,7 @@ def version(self) -> str: @property def invoking_event( self, - ) -> AWSConfigConfigurationChanged | AWSConfigScheduledNotification | AWSConfigOversizedConfiguration: + ) -> AWSConfigConfigurationChanged | AWSConfigScheduledNotification | AWSConfigOversizedConfiguration | None: """The version of the event.""" return get_invoke_event(json.loads(self["invokingEvent"])) From 1b93326a65bebdd6b24f64d32a963f8e56003a8b Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Thu, 27 Apr 2023 23:54:27 +0100 Subject: [PATCH 03/14] feat(dataclass): adding examples and more fields --- .../utilities/data_classes/__init__.py | 4 +- ...aws_config.py => aws_config_rule_event.py} | 128 +++++++++++++++--- docs/utilities/data_classes.md | 21 +++ examples/event_sources/src/aws_config_rule.py | 17 +++ .../src/aws_config_rule_item_changed.json | 13 ++ .../src/aws_config_rule_oversized.json | 12 ++ .../src/aws_config_rule_scheduled.json | 13 ++ 7 files changed, 188 insertions(+), 20 deletions(-) rename aws_lambda_powertools/utilities/data_classes/{aws_config.py => aws_config_rule_event.py} (72%) create mode 100644 examples/event_sources/src/aws_config_rule.py create mode 100644 examples/event_sources/src/aws_config_rule_item_changed.json create mode 100644 examples/event_sources/src/aws_config_rule_oversized.json create mode 100644 examples/event_sources/src/aws_config_rule_scheduled.json diff --git a/aws_lambda_powertools/utilities/data_classes/__init__.py b/aws_lambda_powertools/utilities/data_classes/__init__.py index a0df972a0cb..1fb160d170f 100644 --- a/aws_lambda_powertools/utilities/data_classes/__init__.py +++ b/aws_lambda_powertools/utilities/data_classes/__init__.py @@ -5,7 +5,7 @@ from .alb_event import ALBEvent from .api_gateway_proxy_event import APIGatewayProxyEvent, APIGatewayProxyEventV2 from .appsync_resolver_event import AppSyncResolverEvent -from .aws_config import AWSConfigEvent +from .aws_config_rule_event import AWSConfigRuleEvent from .cloud_watch_custom_widget_event import CloudWatchDashboardCustomWidgetEvent from .cloud_watch_logs_event import CloudWatchLogsEvent from .code_pipeline_job_event import CodePipelineJobEvent @@ -43,5 +43,5 @@ "SNSEvent", "SQSEvent", "event_source", - "AWSConfigEvent", + "AWSConfigRuleEvent", ] diff --git a/aws_lambda_powertools/utilities/data_classes/aws_config.py b/aws_lambda_powertools/utilities/data_classes/aws_config_rule_event.py similarity index 72% rename from aws_lambda_powertools/utilities/data_classes/aws_config.py rename to aws_lambda_powertools/utilities/data_classes/aws_config_rule_event.py index 4da033315bf..10e6f88257f 100644 --- a/aws_lambda_powertools/utilities/data_classes/aws_config.py +++ b/aws_lambda_powertools/utilities/data_classes/aws_config_rule_event.py @@ -24,6 +24,37 @@ def get_invoke_event( return None +class AWSConfigConfigurationChanged(DictWrapper): + @property + def configuration_item_diff(self) -> Dict: + """The version of the event.""" + return self["configurationItemDiff"] + + @property + def configuration_item(self) -> AWSConfigConfigurationItemChanged: + """The version of the event.""" + return AWSConfigConfigurationItemChanged(self["configurationItem"]) + + def raw_configuration_item(self) -> Dict: + """The version of the event.""" + return self["configurationItem"] + + @property + def record_version(self) -> str: + """The version of the event.""" + return self["recordVersion"] + + @property + def message_type(self) -> str: + """The version of the event.""" + return self["messageType"] + + @property + def notification_creation_time(self) -> str: + """The version of the event.""" + return self["notificationCreationTime"] + + class AWSConfigConfigurationItemChanged(DictWrapper): @property def related_events(self) -> List: @@ -116,20 +147,16 @@ def resource_creation_time(self) -> str: return self["resourceCreationTime"] -class AWSConfigConfigurationChanged(DictWrapper): +class AWSConfigScheduledNotification(DictWrapper): @property - def configuration_item_diff(self) -> Dict: + def accountid(self) -> str: """The version of the event.""" - return self["configurationItemDiff"] + return self["awsAccountId"] @property - def configuration_item(self) -> AWSConfigConfigurationItemChanged: - """The version of the event.""" - return AWSConfigConfigurationItemChanged(self["configurationItem"]) - - def raw_configuration_item(self) -> Dict: + def notification_creation_time(self) -> str: """The version of the event.""" - return self["configurationItem"] + return self["notificationCreationTime"] @property def record_version(self) -> str: @@ -141,17 +168,22 @@ def message_type(self) -> str: """The version of the event.""" return self["messageType"] + +class AWSConfigOversizedConfiguration(DictWrapper): @property - def notification_creation_time(self) -> str: + def configuration_item_summary(self) -> AWSConfigOversizedConfigurationItemSummary: """The version of the event.""" - return self["notificationCreationTime"] + return AWSConfigOversizedConfigurationItemSummary(self["configurationItemSummary"]) + @property + def raw_configuration_item_summary(self) -> str: + """The version of the event.""" + return self["configurationItemSummary"] -class AWSConfigScheduledNotification(DictWrapper): @property - def accountid(self) -> str: + def message_type(self) -> str: """The version of the event.""" - return self["awsAccountId"] + return self["messageType"] @property def notification_creation_time(self) -> str: @@ -163,20 +195,80 @@ def record_version(self) -> str: """The version of the event.""" return self["recordVersion"] + +class AWSConfigOversizedConfigurationItemSummary(DictWrapper): @property - def message_type(self) -> str: + def change_type(self) -> str: """The version of the event.""" - return self["messageType"] + return self["changeType"] + @property + def configuration_item_version(self) -> str: + """The version of the event.""" + return self["configurationItemVersion"] + + @property + def configuration_item_capture_time(self) -> str: + """The version of the event.""" + return self["configurationItemCaptureTime"] + + @property + def configuration_state_id(self) -> str: + """The version of the event.""" + return self["configurationStateId"] -class AWSConfigOversizedConfiguration(DictWrapper): @property def accountid(self) -> str: """The version of the event.""" return self["awsAccountId"] + @property + def configuration_item_status(self) -> str: + """The version of the event.""" + return self["configurationItemStatus"] + + @property + def resource_type(self) -> str: + """The version of the event.""" + return self["resourceType"] + + @property + def resource_id(self) -> str: + """The version of the event.""" + return self["resourceId"] + + @property + def resource_name(self) -> str: + """The version of the event.""" + return self["resourceName"] + + @property + def resource_arn(self) -> str: + """The version of the event.""" + return self["ARN"] + + @property + def region(self) -> str: + """The version of the event.""" + return self["awsRegion"] + + @property + def availability_zone(self) -> str: + """The version of the event.""" + return self["availabilityZone"] + + @property + def configuration_state_md5_hash(self) -> str: + """The version of the event.""" + return self["configurationStateMd5Hash"] + + @property + def resource_creation_time(self) -> str: + """The version of the event.""" + return self["resourceCreationTime"] + -class AWSConfigEvent(DictWrapper): +class AWSConfigRuleEvent(DictWrapper): """Events for AWS Config Rules Documentation: -------------- diff --git a/docs/utilities/data_classes.md b/docs/utilities/data_classes.md index 04779ccf0f5..127fe15f315 100644 --- a/docs/utilities/data_classes.md +++ b/docs/utilities/data_classes.md @@ -84,6 +84,7 @@ Log Data Event for Troubleshooting | [Application Load Balancer](#application-load-balancer) | `ALBEvent` | | [AppSync Authorizer](#appsync-authorizer) | `AppSyncAuthorizerEvent` | | [AppSync Resolver](#appsync-resolver) | `AppSyncResolverEvent` | +| [AWS Config Rule](#aws-config-rule) | `AWSConfigRuleEvent` | | [CloudWatch Dashboard Custom Widget](#cloudwatch-dashboard-custom-widget) | `CloudWatchDashboardCustomWidgetEvent` | | [CloudWatch Logs](#cloudwatch-logs) | `CloudWatchLogsEvent` | | [CodePipeline Job Event](#codepipeline-job) | `CodePipelineJobEvent` | @@ -461,6 +462,26 @@ In this example, we also use the new Logger `correlation_id` and built-in `corre } ``` +### AWS Config Rule + +=== "aws_config_rule.py" + ```python hl_lines="1 7" + --8<-- "examples/event_sources/src/aws_config_rule.py" + ``` + +=== "Event - ItemChanged" + ```json + --8<-- "examples/event_sources/src/aws_config_rule_item_changed.json" + ``` +=== "Event - Oversized" + ```json + --8<-- "examples/event_sources/src/aws_config_rule_oversized.json" + ``` +=== "Event - ScheduledNotification" + ```json + --8<-- "examples/event_sources/src/aws_config_rule_scheduled.json" + ``` + ### CloudWatch Dashboard Custom Widget === "app.py" diff --git a/examples/event_sources/src/aws_config_rule.py b/examples/event_sources/src/aws_config_rule.py new file mode 100644 index 00000000000..b81ae39bd25 --- /dev/null +++ b/examples/event_sources/src/aws_config_rule.py @@ -0,0 +1,17 @@ +from aws_lambda_powertools import Logger +from aws_lambda_powertools.utilities.data_classes import ( + AWSConfigRuleEvent, + event_source, +) +from aws_lambda_powertools.utilities.typing import LambdaContext + +logger = Logger() + + +@event_source(data_class=AWSConfigRuleEvent) +def lambda_handler(event: AWSConfigRuleEvent, context: LambdaContext): + message_type = event.invoking_event.message_type + + logger.info(f"Logging {message_type} event rule", invoke_event=event.raw_invoking_event) + + return {"Success": "OK"} diff --git a/examples/event_sources/src/aws_config_rule_item_changed.json b/examples/event_sources/src/aws_config_rule_item_changed.json new file mode 100644 index 00000000000..476a58d6b75 --- /dev/null +++ b/examples/event_sources/src/aws_config_rule_item_changed.json @@ -0,0 +1,13 @@ +{ + "version":"1.0", + "invokingEvent":"{\"configurationItemDiff\":{\"changedProperties\":{\"Configuration.InstanceType\":{\"previousValue\":\"t2.micro\",\"updatedValue\":\"t2.medium\",\"changeType\":\"UPDATE\"},\"Configuration.State.Name\":{\"previousValue\":\"running\",\"updatedValue\":\"stopped\",\"changeType\":\"UPDATE\"},\"Configuration.StateTransitionReason\":{\"previousValue\":\"\",\"updatedValue\":\"User initiated (2023-04-27 15:01:07 GMT)\",\"changeType\":\"UPDATE\"},\"Configuration.StateReason\":{\"previousValue\":null,\"updatedValue\":{\"code\":\"Client.UserInitiatedShutdown\",\"message\":\"Client.UserInitiatedShutdown: User initiated shutdown\"},\"changeType\":\"CREATE\"},\"Configuration.CpuOptions.CoreCount\":{\"previousValue\":1,\"updatedValue\":2,\"changeType\":\"UPDATE\"}},\"changeType\":\"UPDATE\"},\"configurationItem\":{\"relatedEvents\":[],\"relationships\":[{\"resourceId\":\"eipalloc-0ebb4367662263cc1\",\"resourceName\":null,\"resourceType\":\"AWS::EC2::EIP\",\"name\":\"Is attached to ElasticIp\"},{\"resourceId\":\"eni-034dd31c4b17ada8c\",\"resourceName\":null,\"resourceType\":\"AWS::EC2::NetworkInterface\",\"name\":\"Contains NetworkInterface\"},{\"resourceId\":\"eni-09a604c0ec356b06f\",\"resourceName\":null,\"resourceType\":\"AWS::EC2::NetworkInterface\",\"name\":\"Contains NetworkInterface\"},{\"resourceId\":\"sg-0fb295a327d9b4835\",\"resourceName\":null,\"resourceType\":\"AWS::EC2::SecurityGroup\",\"name\":\"Is associated with SecurityGroup\"},{\"resourceId\":\"subnet-cad1f2f4\",\"resourceName\":null,\"resourceType\":\"AWS::EC2::Subnet\",\"name\":\"Is contained in Subnet\"},{\"resourceId\":\"vol-0a288b5eb9fea4b30\",\"resourceName\":null,\"resourceType\":\"AWS::EC2::Volume\",\"name\":\"Is attached to Volume\"},{\"resourceId\":\"vpc-2d96be57\",\"resourceName\":null,\"resourceType\":\"AWS::EC2::VPC\",\"name\":\"Is contained in Vpc\"}],\"configuration\":{\"amiLaunchIndex\":0,\"imageId\":\"ami-09d95fab7fff3776c\",\"instanceId\":\"i-042dd005362091826\",\"instanceType\":\"t2.medium\",\"kernelId\":null,\"keyName\":\"mihaec2\",\"launchTime\":\"2023-04-27T14:57:16.000Z\",\"monitoring\":{\"state\":\"disabled\"},\"placement\":{\"availabilityZone\":\"us-east-1e\",\"affinity\":null,\"groupName\":\"\",\"partitionNumber\":null,\"hostId\":null,\"tenancy\":\"default\",\"spreadDomain\":null,\"hostResourceGroupArn\":null},\"platform\":null,\"privateDnsName\":\"ip-172-31-78-41.ec2.internal\",\"privateIpAddress\":\"172.31.78.41\",\"productCodes\":[],\"publicDnsName\":\"ec2-3-232-229-57.compute-1.amazonaws.com\",\"publicIpAddress\":\"3.232.229.57\",\"ramdiskId\":null,\"state\":{\"code\":80,\"name\":\"stopped\"},\"stateTransitionReason\":\"User initiated (2023-04-27 15:01:07 GMT)\",\"subnetId\":\"subnet-cad1f2f4\",\"vpcId\":\"vpc-2d96be57\",\"architecture\":\"x86_64\",\"blockDeviceMappings\":[{\"deviceName\":\"/dev/xvda\",\"ebs\":{\"attachTime\":\"2020-05-30T15:21:58.000Z\",\"deleteOnTermination\":true,\"status\":\"attached\",\"volumeId\":\"vol-0a288b5eb9fea4b30\"}}],\"clientToken\":\"\",\"ebsOptimized\":false,\"enaSupport\":true,\"hypervisor\":\"xen\",\"iamInstanceProfile\":{\"arn\":\"arn:aws:iam::200984112386:instance-profile/AmazonSSMRoleForInstancesQuickSetup\",\"id\":\"AIPAS5S4WFUBL72S3QXW5\"},\"instanceLifecycle\":null,\"elasticGpuAssociations\":[],\"elasticInferenceAcceleratorAssociations\":[],\"networkInterfaces\":[{\"association\":{\"carrierIp\":null,\"ipOwnerId\":\"200984112386\",\"publicDnsName\":\"ec2-3-232-229-57.compute-1.amazonaws.com\",\"publicIp\":\"3.232.229.57\"},\"attachment\":{\"attachTime\":\"2020-05-30T15:21:57.000Z\",\"attachmentId\":\"eni-attach-0a7e75dc9c1c291a0\",\"deleteOnTermination\":true,\"deviceIndex\":0,\"status\":\"attached\",\"networkCardIndex\":0},\"description\":\"\",\"groups\":[{\"groupName\":\"minhaec2\",\"groupId\":\"sg-0fb295a327d9b4835\"}],\"ipv6Addresses\":[],\"macAddress\":\"06:cf:00:c2:17:db\",\"networkInterfaceId\":\"eni-034dd31c4b17ada8c\",\"ownerId\":\"200984112386\",\"privateDnsName\":\"ip-172-31-78-41.ec2.internal\",\"privateIpAddress\":\"172.31.78.41\",\"privateIpAddresses\":[{\"association\":{\"carrierIp\":null,\"ipOwnerId\":\"200984112386\",\"publicDnsName\":\"ec2-3-232-229-57.compute-1.amazonaws.com\",\"publicIp\":\"3.232.229.57\"},\"primary\":true,\"privateDnsName\":\"ip-172-31-78-41.ec2.internal\",\"privateIpAddress\":\"172.31.78.41\"}],\"sourceDestCheck\":true,\"status\":\"in-use\",\"subnetId\":\"subnet-cad1f2f4\",\"vpcId\":\"vpc-2d96be57\",\"interfaceType\":\"interface\"},{\"association\":null,\"attachment\":{\"attachTime\":\"2020-11-26T23:46:04.000Z\",\"attachmentId\":\"eni-attach-0e6d150ebbd19966e\",\"deleteOnTermination\":false,\"deviceIndex\":1,\"status\":\"attached\",\"networkCardIndex\":0},\"description\":\"MINHAEC2AAAAAA\",\"groups\":[{\"groupName\":\"minhaec2\",\"groupId\":\"sg-0fb295a327d9b4835\"},{\"groupName\":\"default\",\"groupId\":\"sg-88105fa0\"}],\"ipv6Addresses\":[],\"macAddress\":\"06:0a:62:00:64:5f\",\"networkInterfaceId\":\"eni-09a604c0ec356b06f\",\"ownerId\":\"200984112386\",\"privateDnsName\":\"ip-172-31-70-9.ec2.internal\",\"privateIpAddress\":\"172.31.70.9\",\"privateIpAddresses\":[{\"association\":null,\"primary\":true,\"privateDnsName\":\"ip-172-31-70-9.ec2.internal\",\"privateIpAddress\":\"172.31.70.9\"}],\"sourceDestCheck\":true,\"status\":\"in-use\",\"subnetId\":\"subnet-cad1f2f4\",\"vpcId\":\"vpc-2d96be57\",\"interfaceType\":\"interface\"}],\"outpostArn\":null,\"rootDeviceName\":\"/dev/xvda\",\"rootDeviceType\":\"ebs\",\"securityGroups\":[{\"groupName\":\"minhaec2\",\"groupId\":\"sg-0fb295a327d9b4835\"}],\"sourceDestCheck\":true,\"spotInstanceRequestId\":null,\"sriovNetSupport\":null,\"stateReason\":{\"code\":\"Client.UserInitiatedShutdown\",\"message\":\"Client.UserInitiatedShutdown: User initiated shutdown\"},\"tags\":[{\"key\":\"projeto\",\"value\":\"meetup\"},{\"key\":\"Name\",\"value\":\"Minha\"},{\"key\":\"CentroCusto\",\"value\":\"TI\"},{\"key\":\"Setor\",\"value\":\"Desenvolvimento\"}],\"virtualizationType\":\"hvm\",\"cpuOptions\":{\"coreCount\":2,\"threadsPerCore\":1},\"capacityReservationId\":null,\"capacityReservationSpecification\":{\"capacityReservationPreference\":\"open\",\"capacityReservationTarget\":null},\"hibernationOptions\":{\"configured\":false},\"licenses\":[],\"metadataOptions\":{\"state\":\"applied\",\"httpTokens\":\"optional\",\"httpPutResponseHopLimit\":1,\"httpEndpoint\":\"enabled\"},\"enclaveOptions\":{\"enabled\":false},\"bootMode\":null},\"supplementaryConfiguration\":{},\"tags\":{\"projeto\":\"meetup\",\"Setor\":\"Desenvolvimento\",\"CentroCusto\":\"TI\",\"Name\":\"Minha\"},\"configurationItemVersion\":\"1.3\",\"configurationItemCaptureTime\":\"2023-04-27T15:03:11.636Z\",\"configurationStateId\":1682607791636,\"awsAccountId\":\"200984112386\",\"configurationItemStatus\":\"OK\",\"resourceType\":\"AWS::EC2::Instance\",\"resourceId\":\"i-042dd005362091826\",\"resourceName\":null,\"ARN\":\"arn:aws:ec2:us-east-1:200984112386:instance/i-042dd005362091826\",\"awsRegion\":\"us-east-1\",\"availabilityZone\":\"us-east-1e\",\"configurationStateMd5Hash\":\"\",\"resourceCreationTime\":\"2023-04-27T14:57:16.000Z\"},\"notificationCreationTime\":\"2023-04-27T15:03:13.332Z\",\"messageType\":\"ConfigurationItemChangeNotification\",\"recordVersion\":\"1.3\"}", + "ruleParameters":"{\"desiredInstanceType\": \"t2.micro\"}", + "resultToken":"eyJlbmNyeXB0ZWREYXRhIjpbLTQxLDEsLTU3LC0zMCwtMTIxLDUzLDUyLDQ1LC01NywtOCw3MywtODEsLTExNiwtMTAyLC01MiwxMTIsLTQ3LDU4LDY1LC0xMjcsMTAyLDUsLTY5LDQ0LC0xNSwxMTQsNDEs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diI6Wy05NSwzMiwxMDgsOTEsMzUsLTgyLC0zNywyNCwtNDQsLTExNSwtODIsLTEyOCwtMTIyLDMsNTMsLTI0XX19", + "eventLeftScope":false, + "executionRoleArn":"arn:aws:iam::200984112386:role/aws-service-role/config.amazonaws.com/AWSServiceRoleForConfig", + "configRuleArn":"arn:aws:config:us-east-1:200984112386:config-rule/config-rule-i9y8j9", + "configRuleName":"MyRule", + "configRuleId":"config-rule-i9y8j9", + "accountId":"200984112386", + "evaluationMode":"DETECTIVE" + } diff --git a/examples/event_sources/src/aws_config_rule_oversized.json b/examples/event_sources/src/aws_config_rule_oversized.json new file mode 100644 index 00000000000..5eaef4e0015 --- /dev/null +++ b/examples/event_sources/src/aws_config_rule_oversized.json @@ -0,0 +1,12 @@ +{ + "invokingEvent": "{\"configurationItemSummary\": {\"changeType\": \"UPDATE\",\"configurationItemVersion\": \"1.2\",\"configurationItemCaptureTime\":\"2016-10-06T16:46:16.261Z\",\"configurationStateId\": 0,\"awsAccountId\":\"123456789012\",\"configurationItemStatus\": \"OK\",\"resourceType\": \"AWS::EC2::Instance\",\"resourceId\":\"i-00000000\",\"resourceName\":null,\"ARN\":\"arn:aws:ec2:us-west-2:123456789012:instance/i-00000000\",\"awsRegion\": \"us-west-2\",\"availabilityZone\":\"us-west-2a\",\"configurationStateMd5Hash\":\"8f1ee69b287895a0f8bc5753eca68e96\",\"resourceCreationTime\":\"2016-10-06T16:46:10.489Z\"},\"messageType\":\"OversizedConfigurationItemChangeNotification\", \"notificationCreationTime\": \"2016-10-06T16:46:16.261Z\", \"recordVersion\": \"1.0\"}", + "ruleParameters": "{\"myParameterKey\":\"myParameterValue\"}", + "resultToken": "myResultToken", + "eventLeftScope": false, + "executionRoleArn": "arn:aws:iam::123456789012:role/config-role", + "configRuleArn": "arn:aws:config:us-east-2:123456789012:config-rule/config-rule-ec2-managed-instance-inventory", + "configRuleName": "change-triggered-config-rule", + "configRuleId": "config-rule-0123456", + "accountId": "123456789012", + "version": "1.0" +} diff --git a/examples/event_sources/src/aws_config_rule_scheduled.json b/examples/event_sources/src/aws_config_rule_scheduled.json new file mode 100644 index 00000000000..33e857fbab2 --- /dev/null +++ b/examples/event_sources/src/aws_config_rule_scheduled.json @@ -0,0 +1,13 @@ +{ + "version":"1.0", + "invokingEvent":"{\"awsAccountId\":\"200984112386\",\"notificationCreationTime\":\"2023-04-27T13:26:17.741Z\",\"messageType\":\"ScheduledNxotification\",\"recordVersion\":\"1.0\"}", + "ruleParameters":"{\"test\":\"x\"}", + "resultToken":"eyJlbmNyeXB0ZWREYXRhIjpbLTQyLDEyNiw1MiwtMzcsLTI5LDExNCwxMjYsLTk3LDcxLDIyLC0xMTAsMTEyLC0zMSwtOTMsLTQ5LC0xMDEsODIsMyw1NCw0OSwzLC02OSwtNzEsLTcyLDYyLDgxLC03MiwtODEsNTAsMzUsLTUwLC03NSwtMTE4LC0xMTgsNzcsMTIsLTEsMTQsMTIwLC03MCwxMTAsLTMsNTAsLTYwLDEwNSwtNTcsNDUsMTAyLC0xMDksLTYxLC0xMDEsLTYxLDQsNDcsLTg0LC0yNSwxMTIsNTQsLTcxLC0xMDksNDUsMTksMTIzLC0yNiwxMiwtOTYsLTczLDU0LC0xMDksOTIsNDgsLTU5LC04MywtMzIsODIsLTM2LC05MCwxOSw5OCw3Nyw3OCw0MCw4MCw3OCwtMTA1LDg3LC0xMTMsLTExNiwtNzIsMzAsLTY4LC00MCwtODksMTA5LC0xMDgsLTEyOCwyMiw3Miw3NywtMjEsNzYsODksOTQsLTU5LDgxLC0xMjEsLTEwNywtNjcsNjMsLTcsODIsLTg5LC00NiwtMzQsLTkyLDEyMiwtOTAsMTcsLTEyMywyMCwtODUsLTU5LC03MCw4MSwyNyw2Miw3NCwtODAsODAsMzcsNDAsMTE2LDkxLC0yNCw1MSwtNDEsLTc5LDI4LDEyMCw1MywtMTIyLC04MywxMjYsLTc4LDI1LC05OCwtMzYsMTMsMzIsODYsLTI1LDQ4LDMsLTEwMiwtMTYsM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wtMTI1LC00LC00MSw0MiwtNTcsLTEwMyw0NSw3OCwxNCwtMTA2LDExMSw5OCwtOTQsLTcxLDUsNzUsMTksLTEyNCwtMzAsMzQsLTUwLDc1LC04NCwtNTAsLTU2LDUxLC0xNSwtMzYsNjEsLTk0LC03OSwtNDUsMTI2LC03NywtMTA1LC0yLC05MywtNiw4LC0zLDYsLTQyLDQ2LDEyNSw1LC05OCwxMyw2NywtMTAsLTEzLC05NCwtNzgsLTEyNywxMjEsLTI2LC04LC0xMDEsLTkxLDEyMSwtNDAsLTEyNCwtNjQsODQsLTcyLDYzLDE5LC04NF0sIm1hdGVyaWFsU2V0U2VyaWFsTnVtYmVyIjoxLCJpdlBhcmFtZXRlclNwZWMiOnsiaXYiOlszLC0xMCwtODUsMTE0LC05MCwxMTUsNzcsNTUsNTQsMTUsMzgsODQsLTExNiwxNCwtNDAsMjhdfX0=", + "eventLeftScope":false, + "executionRoleArn":"arn:aws:iam::200984112386:role/aws-service-role/config.amazonaws.com/AWSServiceRoleForConfig", + "configRuleArn":"arn:aws:config:us-east-1:200984112386:config-rule/config-rule-pdmyw1", + "configRuleName":"rule-ec2-test", + "configRuleId":"config-rule-pdmyw1", + "accountId":"200984112386", + "evaluationMode":"DETECTIVE" + } From 4393ea0d20de36a6c209c993adbd6a558d5fca2c Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Thu, 27 Apr 2023 23:59:04 +0100 Subject: [PATCH 04/14] feat(dataclass): improving docstring --- .../data_classes/aws_config_rule_event.py | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/aws_lambda_powertools/utilities/data_classes/aws_config_rule_event.py b/aws_lambda_powertools/utilities/data_classes/aws_config_rule_event.py index 10e6f88257f..672c1745522 100644 --- a/aws_lambda_powertools/utilities/data_classes/aws_config_rule_event.py +++ b/aws_lambda_powertools/utilities/data_classes/aws_config_rule_event.py @@ -27,48 +27,48 @@ def get_invoke_event( class AWSConfigConfigurationChanged(DictWrapper): @property def configuration_item_diff(self) -> Dict: - """The version of the event.""" + """The configuration item diff of the ConfigurationItemChangeNotification event.""" return self["configurationItemDiff"] @property def configuration_item(self) -> AWSConfigConfigurationItemChanged: - """The version of the event.""" + """The configuration item of the ConfigurationItemChangeNotification event.""" return AWSConfigConfigurationItemChanged(self["configurationItem"]) def raw_configuration_item(self) -> Dict: - """The version of the event.""" + """The raw configuration item diff of the ConfigurationItemChangeNotification event.""" return self["configurationItem"] @property def record_version(self) -> str: - """The version of the event.""" + """The record version of the ConfigurationItemChangeNotification event.""" return self["recordVersion"] @property def message_type(self) -> str: - """The version of the event.""" + """The message type of the ConfigurationItemChangeNotification event.""" return self["messageType"] @property def notification_creation_time(self) -> str: - """The version of the event.""" + """The notification creation time of the ConfigurationItemChangeNotification event.""" return self["notificationCreationTime"] class AWSConfigConfigurationItemChanged(DictWrapper): @property def related_events(self) -> List: - """The version of the event.""" + """The related events of the ConfigurationItemChangeNotification event.""" return self["relatedEvents"] @property def relationships(self) -> List: - """The version of the event.""" + """The relationships of the ConfigurationItemChangeNotification event.""" return self["relationships"] @property def configuration(self) -> Dict: - """The version of the event.""" + """The configuration of the ConfigurationItemChangeNotification event.""" return self["configuration"] @property @@ -284,12 +284,12 @@ def version(self) -> str: def invoking_event( self, ) -> AWSConfigConfigurationChanged | AWSConfigScheduledNotification | AWSConfigOversizedConfiguration | None: - """The version of the event.""" + """The invoking payload of the event.""" return get_invoke_event(json.loads(self["invokingEvent"])) @property def raw_invoking_event(self) -> str: - """The version of the event.""" + """The raw invoking payload of the event.""" return self["invokingEvent"] @property @@ -299,7 +299,7 @@ def rule_parameters(self) -> Dict: @property def result_token(self) -> str: - """The token of the event.""" + """The result token of the event.""" return self["resultToken"] @property From c5db6b079240126f34cc412fe8a4b16d447c1254 Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Fri, 28 Apr 2023 01:06:00 +0100 Subject: [PATCH 05/14] feat(dataclass): tests and small fixes --- .../awsConfigRuleConfigurationChanged.json | 13 ++++++ .../awsConfigRuleOversizedConfiguration.json | 12 ++++++ tests/events/awsConfigRuleScheduled.json | 13 ++++++ tests/functional/test_data_classes.py | 42 +++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 tests/events/awsConfigRuleConfigurationChanged.json create mode 100644 tests/events/awsConfigRuleOversizedConfiguration.json create mode 100644 tests/events/awsConfigRuleScheduled.json diff --git a/tests/events/awsConfigRuleConfigurationChanged.json b/tests/events/awsConfigRuleConfigurationChanged.json new file mode 100644 index 00000000000..cbf7abf67aa --- /dev/null +++ b/tests/events/awsConfigRuleConfigurationChanged.json @@ -0,0 +1,13 @@ +{ + "version":"1.0", + "invokingEvent":"{\"configurationItemDiff\":{\"changedProperties\":{\"Configuration.InstanceType\":{\"previousValue\":\"t2.micro\",\"updatedValue\":\"t2.medium\",\"changeType\":\"UPDATE\"},\"Configuration.State.Name\":{\"previousValue\":\"running\",\"updatedValue\":\"stopped\",\"changeType\":\"UPDATE\"},\"Configuration.StateTransitionReason\":{\"previousValue\":\"\",\"updatedValue\":\"User initiated (2023-04-27 15:01:07 GMT)\",\"changeType\":\"UPDATE\"},\"Configuration.StateReason\":{\"previousValue\":null,\"updatedValue\":{\"code\":\"Client.UserInitiatedShutdown\",\"message\":\"Client.UserInitiatedShutdown: User initiated shutdown\"},\"changeType\":\"CREATE\"},\"Configuration.CpuOptions.CoreCount\":{\"previousValue\":1,\"updatedValue\":2,\"changeType\":\"UPDATE\"}},\"changeType\":\"UPDATE\"},\"configurationItem\":{\"relatedEvents\":[],\"relationships\":[{\"resourceId\":\"eipalloc-0ebb4367662263cc1\",\"resourceName\":null,\"resourceType\":\"AWS::EC2::EIP\",\"name\":\"Is attached to ElasticIp\"},{\"resourceId\":\"eni-034dd31c4b17ada8c\",\"resourceName\":null,\"resourceType\":\"AWS::EC2::NetworkInterface\",\"name\":\"Contains NetworkInterface\"},{\"resourceId\":\"eni-09a604c0ec356b06f\",\"resourceName\":null,\"resourceType\":\"AWS::EC2::NetworkInterface\",\"name\":\"Contains NetworkInterface\"},{\"resourceId\":\"sg-0fb295a327d9b4835\",\"resourceName\":null,\"resourceType\":\"AWS::EC2::SecurityGroup\",\"name\":\"Is associated with SecurityGroup\"},{\"resourceId\":\"subnet-cad1f2f4\",\"resourceName\":null,\"resourceType\":\"AWS::EC2::Subnet\",\"name\":\"Is contained in Subnet\"},{\"resourceId\":\"vol-0a288b5eb9fea4b30\",\"resourceName\":null,\"resourceType\":\"AWS::EC2::Volume\",\"name\":\"Is attached to Volume\"},{\"resourceId\":\"vpc-2d96be57\",\"resourceName\":null,\"resourceType\":\"AWS::EC2::VPC\",\"name\":\"Is contained in Vpc\"}],\"configuration\":{\"amiLaunchIndex\":0,\"imageId\":\"ami-09d95fab7fff3776c\",\"instanceId\":\"i-042dd005362091826\",\"instanceType\":\"t2.medium\",\"kernelId\":null,\"keyName\":\"mihaec2\",\"launchTime\":\"2023-04-27T14:57:16.000Z\",\"monitoring\":{\"state\":\"disabled\"},\"placement\":{\"availabilityZone\":\"us-east-1e\",\"affinity\":null,\"groupName\":\"\",\"partitionNumber\":null,\"hostId\":null,\"tenancy\":\"default\",\"spreadDomain\":null,\"hostResourceGroupArn\":null},\"platform\":null,\"privateDnsName\":\"ip-172-31-78-41.ec2.internal\",\"privateIpAddress\":\"172.31.78.41\",\"productCodes\":[],\"publicDnsName\":\"ec2-3-232-229-57.compute-1.amazonaws.com\",\"publicIpAddress\":\"3.232.229.57\",\"ramdiskId\":null,\"state\":{\"code\":80,\"name\":\"stopped\"},\"stateTransitionReason\":\"User initiated (2023-04-27 15:01:07 GMT)\",\"subnetId\":\"subnet-cad1f2f4\",\"vpcId\":\"vpc-2d96be57\",\"architecture\":\"x86_64\",\"blockDeviceMappings\":[{\"deviceName\":\"/dev/xvda\",\"ebs\":{\"attachTime\":\"2020-05-30T15:21:58.000Z\",\"deleteOnTermination\":true,\"status\":\"attached\",\"volumeId\":\"vol-0a288b5eb9fea4b30\"}}],\"clientToken\":\"\",\"ebsOptimized\":false,\"enaSupport\":true,\"hypervisor\":\"xen\",\"iamInstanceProfile\":{\"arn\":\"arn:aws:iam::0123456789012:instance-profile/AmazonSSMRoleForInstancesQuickSetup\",\"id\":\"AIPAS5S4WFUBL72S3QXW5\"},\"instanceLifecycle\":null,\"elasticGpuAssociations\":[],\"elasticInferenceAcceleratorAssociations\":[],\"networkInterfaces\":[{\"association\":{\"carrierIp\":null,\"ipOwnerId\":\"0123456789012\",\"publicDnsName\":\"ec2-3-232-229-57.compute-1.amazonaws.com\",\"publicIp\":\"3.232.229.57\"},\"attachment\":{\"attachTime\":\"2020-05-30T15:21:57.000Z\",\"attachmentId\":\"eni-attach-0a7e75dc9c1c291a0\",\"deleteOnTermination\":true,\"deviceIndex\":0,\"status\":\"attached\",\"networkCardIndex\":0},\"description\":\"\",\"groups\":[{\"groupName\":\"minhaec2\",\"groupId\":\"sg-0fb295a327d9b4835\"}],\"ipv6Addresses\":[],\"macAddress\":\"06:cf:00:c2:17:db\",\"networkInterfaceId\":\"eni-034dd31c4b17ada8c\",\"ownerId\":\"0123456789012\",\"privateDnsName\":\"ip-172-31-78-41.ec2.internal\",\"privateIpAddress\":\"172.31.78.41\",\"privateIpAddresses\":[{\"association\":{\"carrierIp\":null,\"ipOwnerId\":\"0123456789012\",\"publicDnsName\":\"ec2-3-232-229-57.compute-1.amazonaws.com\",\"publicIp\":\"3.232.229.57\"},\"primary\":true,\"privateDnsName\":\"ip-172-31-78-41.ec2.internal\",\"privateIpAddress\":\"172.31.78.41\"}],\"sourceDestCheck\":true,\"status\":\"in-use\",\"subnetId\":\"subnet-cad1f2f4\",\"vpcId\":\"vpc-2d96be57\",\"interfaceType\":\"interface\"},{\"association\":null,\"attachment\":{\"attachTime\":\"2020-11-26T23:46:04.000Z\",\"attachmentId\":\"eni-attach-0e6d150ebbd19966e\",\"deleteOnTermination\":false,\"deviceIndex\":1,\"status\":\"attached\",\"networkCardIndex\":0},\"description\":\"MINHAEC2AAAAAA\",\"groups\":[{\"groupName\":\"minhaec2\",\"groupId\":\"sg-0fb295a327d9b4835\"},{\"groupName\":\"default\",\"groupId\":\"sg-88105fa0\"}],\"ipv6Addresses\":[],\"macAddress\":\"06:0a:62:00:64:5f\",\"networkInterfaceId\":\"eni-09a604c0ec356b06f\",\"ownerId\":\"0123456789012\",\"privateDnsName\":\"ip-172-31-70-9.ec2.internal\",\"privateIpAddress\":\"172.31.70.9\",\"privateIpAddresses\":[{\"association\":null,\"primary\":true,\"privateDnsName\":\"ip-172-31-70-9.ec2.internal\",\"privateIpAddress\":\"172.31.70.9\"}],\"sourceDestCheck\":true,\"status\":\"in-use\",\"subnetId\":\"subnet-cad1f2f4\",\"vpcId\":\"vpc-2d96be57\",\"interfaceType\":\"interface\"}],\"outpostArn\":null,\"rootDeviceName\":\"/dev/xvda\",\"rootDeviceType\":\"ebs\",\"securityGroups\":[{\"groupName\":\"minhaec2\",\"groupId\":\"sg-0fb295a327d9b4835\"}],\"sourceDestCheck\":true,\"spotInstanceRequestId\":null,\"sriovNetSupport\":null,\"stateReason\":{\"code\":\"Client.UserInitiatedShutdown\",\"message\":\"Client.UserInitiatedShutdown: User initiated shutdown\"},\"tags\":[{\"key\":\"projeto\",\"value\":\"meetup\"},{\"key\":\"Name\",\"value\":\"Minha\"},{\"key\":\"CentroCusto\",\"value\":\"TI\"},{\"key\":\"Setor\",\"value\":\"Desenvolvimento\"}],\"virtualizationType\":\"hvm\",\"cpuOptions\":{\"coreCount\":2,\"threadsPerCore\":1},\"capacityReservationId\":null,\"capacityReservationSpecification\":{\"capacityReservationPreference\":\"open\",\"capacityReservationTarget\":null},\"hibernationOptions\":{\"configured\":false},\"licenses\":[],\"metadataOptions\":{\"state\":\"applied\",\"httpTokens\":\"optional\",\"httpPutResponseHopLimit\":1,\"httpEndpoint\":\"enabled\"},\"enclaveOptions\":{\"enabled\":false},\"bootMode\":null},\"supplementaryConfiguration\":{},\"tags\":{\"projeto\":\"meetup\",\"Setor\":\"Desenvolvimento\",\"CentroCusto\":\"TI\",\"Name\":\"Minha\"},\"configurationItemVersion\":\"1.3\",\"configurationItemCaptureTime\":\"2023-04-27T15:03:11.636Z\",\"configurationStateId\":1682607791636,\"awsAccountId\":\"0123456789012\",\"configurationItemStatus\":\"OK\",\"resourceType\":\"AWS::EC2::Instance\",\"resourceId\":\"i-042dd005362091826\",\"resourceName\":null,\"ARN\":\"arn:aws:ec2:us-east-1:0123456789012:instance/i-042dd005362091826\",\"awsRegion\":\"us-east-1\",\"availabilityZone\":\"us-east-1e\",\"configurationStateMd5Hash\":\"\",\"resourceCreationTime\":\"2023-04-27T14:57:16.000Z\"},\"notificationCreationTime\":\"2023-04-27T15:03:13.332Z\",\"messageType\":\"ConfigurationItemChangeNotification\",\"recordVersion\":\"1.3\"}", + "ruleParameters":"{\"desiredInstanceType\": \"t2.micro\"}", + "resultToken":"eyJlbmNyeXB0ZWREYXRhIjpbLTQxLDEsLTU3LC0zMCwtMTIxLDUzLDUyLDQ1LC01NywtOCw3MywtODEsLTExNiwtMTAyLC01MiwxMTIsLTQ3LDU4LDY1LC0xMjcsMTAyLDUsLTY5LDQ0LC0xNSwxMTQsNDEsLTksMTExLC0zMCw2NSwtNzUsLTM1LDU0LDEwNSwtODksODYsNDAsLTEwNSw5OCw2NSwtMTE5LC02OSwyNCw2NiwtMjAsODAsLTExMiwtNzgsLTgwLDQzLC01NywzMCwtMjUsODIsLTEwLDMsLTQsLTg1LC01MywtMzcsLTkwLC04OCwtOTgsLTk4LC00MSwxOSwxMTYsNjIsLTIzLC0xMjEsLTEwOCw1NywtNTgsLTUyLDI5LDEwMSwxMjIsLTU2LC03MSwtODEsLTQ3LDc3LC0yMiwtMTI0LC0zLC04NiwtMTIyLC00MCwtODksLTEwMSw1NywtMTI3LC0zNywtMzcsLTMxLC05OCwtMzEsMTEsLTEyNSwwLDEwOCwtMzIsNjQsNjIsLTIyLDAsNDcsLTEwNiwtMTAwLDEwNCwxNCw1OCwxMjIsLTEwLC01MCwtOTAsLTgwLC01MCwtNS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2LDEwLC04MCwtNzAsMTAyLDg4LC0xMjYsODcsLTI3LC0xMDEsLTk0LC0zNSwtMTA2LC02LC03MiwtODYsNTAsMTE2LC0yOCw5MCwxMywtMTIwLDYsMjcsOTIsNTYsLTkwLDM5LDQ5LC0xMywtODYsLTI1LC04NiwxMTMsLTEzLDQxLC0xMTksOTQsLTk0LC0xMDMsLTgzLC02MCwxMjcsLTE1LC0zOSwxMTksLTk1LDI3LDQ0LDExNiwxMDksNywtMTAyLC0xNyw0OCwtODIsLTMxLC04LC02OSwzNSw5NCw1NCwtNTUsMSwtMTE5LDU3LC0xMDgsLTMsLTkxLC0xMjIsLTUzLC04OCw0LC05NywtMzUsMTI2LDExOSw1OSwtMSw4NSw3MywtNTgsLTEyMCwtNjQsMTE5LC0xMTIsOTIsMTksOSwtNjYsLTkyLDEwOCwtMTEsLTQyLDExMSwtMTA0LC0xMjAsMjcsLTEwMywtNjksMTksMTExLDEyLDIzLDEwNyw1NCw0MSwtMjYsNjAsLTMxLC01XSwibWF0ZXJpYWxTZXRTZXJpYWxOdW1iZXIiOjEsIml2UGFyYW1ldGVyU3BlYyI6eyJpdiI6Wy05NSwzMiwxMDgsOTEsMzUsLTgyLC0zNywyNCwtNDQsLTExNSwtODIsLTEyOCwtMTIyLDMsNTMsLTI0XX19", + "eventLeftScope":false, + "executionRoleArn":"arn:aws:iam::0123456789012:role/aws-service-role/config.amazonaws.com/AWSServiceRoleForConfig", + "configRuleArn":"arn:aws:config:us-east-1:0123456789012:config-rule/config-rule-i9y8j9", + "configRuleName":"MyRule", + "configRuleId":"config-rule-i9y8j9", + "accountId":"0123456789012", + "evaluationMode":"DETECTIVE" + } diff --git a/tests/events/awsConfigRuleOversizedConfiguration.json b/tests/events/awsConfigRuleOversizedConfiguration.json new file mode 100644 index 00000000000..5eaef4e0015 --- /dev/null +++ b/tests/events/awsConfigRuleOversizedConfiguration.json @@ -0,0 +1,12 @@ +{ + "invokingEvent": "{\"configurationItemSummary\": {\"changeType\": \"UPDATE\",\"configurationItemVersion\": \"1.2\",\"configurationItemCaptureTime\":\"2016-10-06T16:46:16.261Z\",\"configurationStateId\": 0,\"awsAccountId\":\"123456789012\",\"configurationItemStatus\": \"OK\",\"resourceType\": \"AWS::EC2::Instance\",\"resourceId\":\"i-00000000\",\"resourceName\":null,\"ARN\":\"arn:aws:ec2:us-west-2:123456789012:instance/i-00000000\",\"awsRegion\": \"us-west-2\",\"availabilityZone\":\"us-west-2a\",\"configurationStateMd5Hash\":\"8f1ee69b287895a0f8bc5753eca68e96\",\"resourceCreationTime\":\"2016-10-06T16:46:10.489Z\"},\"messageType\":\"OversizedConfigurationItemChangeNotification\", \"notificationCreationTime\": \"2016-10-06T16:46:16.261Z\", \"recordVersion\": \"1.0\"}", + "ruleParameters": "{\"myParameterKey\":\"myParameterValue\"}", + "resultToken": "myResultToken", + "eventLeftScope": false, + "executionRoleArn": "arn:aws:iam::123456789012:role/config-role", + "configRuleArn": "arn:aws:config:us-east-2:123456789012:config-rule/config-rule-ec2-managed-instance-inventory", + "configRuleName": "change-triggered-config-rule", + "configRuleId": "config-rule-0123456", + "accountId": "123456789012", + "version": "1.0" +} diff --git a/tests/events/awsConfigRuleScheduled.json b/tests/events/awsConfigRuleScheduled.json new file mode 100644 index 00000000000..f21ed9fe57f --- /dev/null +++ b/tests/events/awsConfigRuleScheduled.json @@ -0,0 +1,13 @@ +{ + "version":"1.0", + "invokingEvent":"{\"awsAccountId\":\"0123456789012\",\"notificationCreationTime\":\"2023-04-27T13:26:17.741Z\",\"messageType\":\"ScheduledNxotification\",\"recordVersion\":\"1.0\"}", + "ruleParameters":"{\"test\":\"x\"}", + "resultToken":"eyJlbmNyeXB0ZWREYXRhIjpbLTQyLDEyNiw1MiwtMzcsLTI5LDExNCwxMjYsLTk3LDcxLDIyLC0xMTAsMTEyLC0zMSwtOTMsLTQ5LC0xMDEsODIsMyw1NCw0OSwzLC02OSwtNzEsLTcyLDYyLDgxLC03MiwtODEsNTAsMzUsLTUwLC03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sMjhdfX0=", + "eventLeftScope":false, + "executionRoleArn":"arn:aws:iam::0123456789012:role/aws-service-role/config.amazonaws.com/AWSServiceRoleForConfig", + "configRuleArn":"arn:aws:config:us-east-1:0123456789012:config-rule/config-rule-pdmyw1", + "configRuleName":"rule-ec2-test", + "configRuleId":"config-rule-pdmyw1", + "accountId":"0123456789012", + "evaluationMode":"DETECTIVE" + } diff --git a/tests/functional/test_data_classes.py b/tests/functional/test_data_classes.py index 068e8738fad..8146860ea8c 100644 --- a/tests/functional/test_data_classes.py +++ b/tests/functional/test_data_classes.py @@ -14,6 +14,7 @@ APIGatewayProxyEvent, APIGatewayProxyEventV2, AppSyncResolverEvent, + AWSConfigRuleEvent, CloudWatchDashboardCustomWidgetEvent, CloudWatchLogsEvent, CodePipelineJobEvent, @@ -1997,3 +1998,44 @@ def test_api_gateway_route_arn_parser(): details = parse_api_gateway_arn(arn) assert details.resource == "" assert details.arn == arn + "/" + + +def test_aws_config_rule_configuration_changed(): + """Check API Gateway authorizer token event""" + event = AWSConfigRuleEvent(load_event("awsConfigRuleConfigurationChanged.json")) + + invoking_event = json.loads(event["invokingEvent"]) + + assert event.invoking_event.message_type == invoking_event["messageType"] + assert event.accountid == event["accountId"] + assert event.version == event["version"] + assert event.execution_role_arn == event["executionRoleArn"] + assert hasattr(event.invoking_event, "configuration_item_diff") + assert hasattr(event.invoking_event, "configuration_item") + assert hasattr(event.invoking_event.configuration_item, "configuration") + + +def test_aws_config_rule_oversized_configuration(): + """Check API Gateway authorizer token event""" + event = AWSConfigRuleEvent(load_event("awsConfigRuleOversizedConfiguration.json")) + + invoking_event = json.loads(event["invokingEvent"]) + + assert event.invoking_event.message_type == invoking_event["messageType"] + assert event.accountid == event["accountId"] + assert event.version == event["version"] + assert event.execution_role_arn == event["executionRoleArn"] + assert hasattr(event.invoking_event, "configuration_item_summary") + assert hasattr(event.invoking_event.configuration_item_summary, "change_type") + + +def test_aws_config_rule_scheduled(): + """Check API Gateway authorizer token event""" + event = AWSConfigRuleEvent(load_event("awsConfigRuleOversizedConfiguration.json")) + + invoking_event = json.loads(event["invokingEvent"]) + + assert event.invoking_event.message_type == invoking_event["messageType"] + assert event.accountid == event["accountId"] + assert event.version == event["version"] + assert event.execution_role_arn == event["executionRoleArn"] From 440f0d13f71bda7ee642e0cfda52cfdcd26e61bf Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Fri, 28 Apr 2023 01:08:30 +0100 Subject: [PATCH 06/14] feat(dataclass): tests and small fixes --- .../data_classes/aws_config_rule_event.py | 87 +++++++++---------- .../src/aws_config_rule_item_changed.json | 8 +- .../src/aws_config_rule_scheduled.json | 8 +- tests/functional/test_data_classes.py | 8 +- 4 files changed, 54 insertions(+), 57 deletions(-) diff --git a/aws_lambda_powertools/utilities/data_classes/aws_config_rule_event.py b/aws_lambda_powertools/utilities/data_classes/aws_config_rule_event.py index 672c1745522..2a1a5965d05 100644 --- a/aws_lambda_powertools/utilities/data_classes/aws_config_rule_event.py +++ b/aws_lambda_powertools/utilities/data_classes/aws_config_rule_event.py @@ -8,20 +8,17 @@ def get_invoke_event( invoking_event: dict, -) -> AWSConfigConfigurationChanged | AWSConfigScheduledNotification | AWSConfigOversizedConfiguration | None: +) -> AWSConfigConfigurationChanged | AWSConfigScheduledNotification | AWSConfigOversizedConfiguration: message_type = invoking_event.get("messageType") - if message_type == "ConfigurationItemChangeNotification": - return AWSConfigConfigurationChanged(invoking_event) - if message_type == "ScheduledNotification": return AWSConfigScheduledNotification(invoking_event) if message_type == "OversizedConfigurationItemChangeNotification": return AWSConfigOversizedConfiguration(invoking_event) - # In case of a unknown event - return None + # Default return is ConfigurationChanged + return AWSConfigConfigurationChanged(invoking_event) class AWSConfigConfigurationChanged(DictWrapper): @@ -73,198 +70,198 @@ def configuration(self) -> Dict: @property def supplementary_configuration(self) -> Dict: - """The version of the event.""" + """The supplementary configuration of the ConfigurationItemChangeNotification event.""" return self["supplementaryConfiguration"] @property def tags(self) -> Dict: - """The version of the event.""" + """The tags of the ConfigurationItemChangeNotification event.""" return self["tags"] @property def configuration_item_version(self) -> str: - """The version of the event.""" + """The configuration item version of the ConfigurationItemChangeNotification event.""" return self["configurationItemVersion"] @property def configuration_item_capture_time(self) -> str: - """The version of the event.""" + """The configuration item capture time of the ConfigurationItemChangeNotification event.""" return self["configurationItemCaptureTime"] @property def configuration_state_id(self) -> str: - """The version of the event.""" + """The configuration state id of the ConfigurationItemChangeNotification event.""" return self["configurationStateId"] @property def accountid(self) -> str: - """The version of the event.""" + """The accountid of the ConfigurationItemChangeNotification event.""" return self["awsAccountId"] @property def configuration_item_status(self) -> str: - """The version of the event.""" + """The configuration item status of the ConfigurationItemChangeNotification event.""" return self["configurationItemStatus"] @property def resource_type(self) -> str: - """The version of the event.""" + """The resource type of the ConfigurationItemChangeNotification event.""" return self["resourceType"] @property def resource_id(self) -> str: - """The version of the event.""" + """The resource id of the ConfigurationItemChangeNotification event.""" return self["resourceId"] @property def resource_name(self) -> str: - """The version of the event.""" + """The resource name of the ConfigurationItemChangeNotification event.""" return self["resourceName"] @property def resource_arn(self) -> str: - """The version of the event.""" + """The resource arn of the ConfigurationItemChangeNotification event.""" return self["ARN"] @property def region(self) -> str: - """The version of the event.""" + """The region of the ConfigurationItemChangeNotification event.""" return self["awsRegion"] @property def availability_zone(self) -> str: - """The version of the event.""" + """The availability zone of the ConfigurationItemChangeNotification event.""" return self["availabilityZone"] @property def configuration_state_md5_hash(self) -> str: - """The version of the event.""" + """The md5 hash of the state of the ConfigurationItemChangeNotification event.""" return self["configurationStateMd5Hash"] @property def resource_creation_time(self) -> str: - """The version of the event.""" + """The resource creation time of the ConfigurationItemChangeNotification event.""" return self["resourceCreationTime"] class AWSConfigScheduledNotification(DictWrapper): @property def accountid(self) -> str: - """The version of the event.""" + """The accountid of the ScheduledNotification event.""" return self["awsAccountId"] @property def notification_creation_time(self) -> str: - """The version of the event.""" + """The notification creation time of the ScheduledNotification event.""" return self["notificationCreationTime"] @property def record_version(self) -> str: - """The version of the event.""" + """The record version of the ScheduledNotification event.""" return self["recordVersion"] @property def message_type(self) -> str: - """The version of the event.""" + """The message type of the ScheduledNotification event.""" return self["messageType"] class AWSConfigOversizedConfiguration(DictWrapper): @property def configuration_item_summary(self) -> AWSConfigOversizedConfigurationItemSummary: - """The version of the event.""" + """The configuration item summary of the OversizedConfiguration event.""" return AWSConfigOversizedConfigurationItemSummary(self["configurationItemSummary"]) @property def raw_configuration_item_summary(self) -> str: - """The version of the event.""" + """The raw configuration item summary of the OversizedConfiguration event.""" return self["configurationItemSummary"] @property def message_type(self) -> str: - """The version of the event.""" + """The message type of the OversizedConfiguration event.""" return self["messageType"] @property def notification_creation_time(self) -> str: - """The version of the event.""" + """The notification creation time of the OversizedConfiguration event.""" return self["notificationCreationTime"] @property def record_version(self) -> str: - """The version of the event.""" + """The record version of the OversizedConfiguration event.""" return self["recordVersion"] class AWSConfigOversizedConfigurationItemSummary(DictWrapper): @property def change_type(self) -> str: - """The version of the event.""" + """The change type of the OversizedConfiguration event.""" return self["changeType"] @property def configuration_item_version(self) -> str: - """The version of the event.""" + """The configuration item version of the OversizedConfiguration event.""" return self["configurationItemVersion"] @property def configuration_item_capture_time(self) -> str: - """The version of the event.""" + """The configuration item capture time of the OversizedConfiguration event.""" return self["configurationItemCaptureTime"] @property def configuration_state_id(self) -> str: - """The version of the event.""" + """The configuration state id of the OversizedConfiguration event.""" return self["configurationStateId"] @property def accountid(self) -> str: - """The version of the event.""" + """The accountid of the OversizedConfiguration event.""" return self["awsAccountId"] @property def configuration_item_status(self) -> str: - """The version of the event.""" + """The configuration item status of the OversizedConfiguration event.""" return self["configurationItemStatus"] @property def resource_type(self) -> str: - """The version of the event.""" + """The resource type of the OversizedConfiguration event.""" return self["resourceType"] @property def resource_id(self) -> str: - """The version of the event.""" + """The resource id of the OversizedConfiguration event.""" return self["resourceId"] @property def resource_name(self) -> str: - """The version of the event.""" + """The resource name of the OversizedConfiguration event.""" return self["resourceName"] @property def resource_arn(self) -> str: - """The version of the event.""" + """The resource arn of the OversizedConfiguration event.""" return self["ARN"] @property def region(self) -> str: - """The version of the event.""" + """The region of the OversizedConfiguration event.""" return self["awsRegion"] @property def availability_zone(self) -> str: - """The version of the event.""" + """The availability zone of the OversizedConfiguration event.""" return self["availabilityZone"] @property def configuration_state_md5_hash(self) -> str: - """The version of the event.""" + """The state md5 hash of the OversizedConfiguration event.""" return self["configurationStateMd5Hash"] @property def resource_creation_time(self) -> str: - """The version of the event.""" + """The resource creation time of the OversizedConfiguration event.""" return self["resourceCreationTime"] @@ -283,7 +280,7 @@ def version(self) -> str: @property def invoking_event( self, - ) -> AWSConfigConfigurationChanged | AWSConfigScheduledNotification | AWSConfigOversizedConfiguration | None: + ) -> AWSConfigConfigurationChanged | AWSConfigScheduledNotification | AWSConfigOversizedConfiguration: """The invoking payload of the event.""" return get_invoke_event(json.loads(self["invokingEvent"])) diff --git a/examples/event_sources/src/aws_config_rule_item_changed.json b/examples/event_sources/src/aws_config_rule_item_changed.json index 476a58d6b75..cbf7abf67aa 100644 --- a/examples/event_sources/src/aws_config_rule_item_changed.json +++ b/examples/event_sources/src/aws_config_rule_item_changed.json @@ -1,13 +1,13 @@ { "version":"1.0", - "invokingEvent":"{\"configurationItemDiff\":{\"changedProperties\":{\"Configuration.InstanceType\":{\"previousValue\":\"t2.micro\",\"updatedValue\":\"t2.medium\",\"changeType\":\"UPDATE\"},\"Configuration.State.Name\":{\"previousValue\":\"running\",\"updatedValue\":\"stopped\",\"changeType\":\"UPDATE\"},\"Configuration.StateTransitionReason\":{\"previousValue\":\"\",\"updatedValue\":\"User initiated (2023-04-27 15:01:07 GMT)\",\"changeType\":\"UPDATE\"},\"Configuration.StateReason\":{\"previousValue\":null,\"updatedValue\":{\"code\":\"Client.UserInitiatedShutdown\",\"message\":\"Client.UserInitiatedShutdown: User initiated shutdown\"},\"changeType\":\"CREATE\"},\"Configuration.CpuOptions.CoreCount\":{\"previousValue\":1,\"updatedValue\":2,\"changeType\":\"UPDATE\"}},\"changeType\":\"UPDATE\"},\"configurationItem\":{\"relatedEvents\":[],\"relationships\":[{\"resourceId\":\"eipalloc-0ebb4367662263cc1\",\"resourceName\":null,\"resourceType\":\"AWS::EC2::EIP\",\"name\":\"Is attached to ElasticIp\"},{\"resourceId\":\"eni-034dd31c4b17ada8c\",\"resourceName\":null,\"resourceType\":\"AWS::EC2::NetworkInterface\",\"name\":\"Contains NetworkInterface\"},{\"resourceId\":\"eni-09a604c0ec356b06f\",\"resourceName\":null,\"resourceType\":\"AWS::EC2::NetworkInterface\",\"name\":\"Contains NetworkInterface\"},{\"resourceId\":\"sg-0fb295a327d9b4835\",\"resourceName\":null,\"resourceType\":\"AWS::EC2::SecurityGroup\",\"name\":\"Is associated with SecurityGroup\"},{\"resourceId\":\"subnet-cad1f2f4\",\"resourceName\":null,\"resourceType\":\"AWS::EC2::Subnet\",\"name\":\"Is contained in Subnet\"},{\"resourceId\":\"vol-0a288b5eb9fea4b30\",\"resourceName\":null,\"resourceType\":\"AWS::EC2::Volume\",\"name\":\"Is attached to Volume\"},{\"resourceId\":\"vpc-2d96be57\",\"resourceName\":null,\"resourceType\":\"AWS::EC2::VPC\",\"name\":\"Is contained in Vpc\"}],\"configuration\":{\"amiLaunchIndex\":0,\"imageId\":\"ami-09d95fab7fff3776c\",\"instanceId\":\"i-042dd005362091826\",\"instanceType\":\"t2.medium\",\"kernelId\":null,\"keyName\":\"mihaec2\",\"launchTime\":\"2023-04-27T14:57:16.000Z\",\"monitoring\":{\"state\":\"disabled\"},\"placement\":{\"availabilityZone\":\"us-east-1e\",\"affinity\":null,\"groupName\":\"\",\"partitionNumber\":null,\"hostId\":null,\"tenancy\":\"default\",\"spreadDomain\":null,\"hostResourceGroupArn\":null},\"platform\":null,\"privateDnsName\":\"ip-172-31-78-41.ec2.internal\",\"privateIpAddress\":\"172.31.78.41\",\"productCodes\":[],\"publicDnsName\":\"ec2-3-232-229-57.compute-1.amazonaws.com\",\"publicIpAddress\":\"3.232.229.57\",\"ramdiskId\":null,\"state\":{\"code\":80,\"name\":\"stopped\"},\"stateTransitionReason\":\"User initiated (2023-04-27 15:01:07 GMT)\",\"subnetId\":\"subnet-cad1f2f4\",\"vpcId\":\"vpc-2d96be57\",\"architecture\":\"x86_64\",\"blockDeviceMappings\":[{\"deviceName\":\"/dev/xvda\",\"ebs\":{\"attachTime\":\"2020-05-30T15:21:58.000Z\",\"deleteOnTermination\":true,\"status\":\"attached\",\"volumeId\":\"vol-0a288b5eb9fea4b30\"}}],\"clientToken\":\"\",\"ebsOptimized\":false,\"enaSupport\":true,\"hypervisor\":\"xen\",\"iamInstanceProfile\":{\"arn\":\"arn:aws:iam::200984112386:instance-profile/AmazonSSMRoleForInstancesQuickSetup\",\"id\":\"AIPAS5S4WFUBL72S3QXW5\"},\"instanceLifecycle\":null,\"elasticGpuAssociations\":[],\"elasticInferenceAcceleratorAssociations\":[],\"networkInterfaces\":[{\"association\":{\"carrierIp\":null,\"ipOwnerId\":\"200984112386\",\"publicDnsName\":\"ec2-3-232-229-57.compute-1.amazonaws.com\",\"publicIp\":\"3.232.229.57\"},\"attachment\":{\"attachTime\":\"2020-05-30T15:21:57.000Z\",\"attachmentId\":\"eni-attach-0a7e75dc9c1c291a0\",\"deleteOnTermination\":true,\"deviceIndex\":0,\"status\":\"attached\",\"networkCardIndex\":0},\"description\":\"\",\"groups\":[{\"groupName\":\"minhaec2\",\"groupId\":\"sg-0fb295a327d9b4835\"}],\"ipv6Addresses\":[],\"macAddress\":\"06:cf:00:c2:17:db\",\"networkInterfaceId\":\"eni-034dd31c4b17ada8c\",\"ownerId\":\"200984112386\",\"privateDnsName\":\"ip-172-31-78-41.ec2.internal\",\"privateIpAddress\":\"172.31.78.41\",\"privateIpAddresses\":[{\"association\":{\"carrierIp\":null,\"ipOwnerId\":\"200984112386\",\"publicDnsName\":\"ec2-3-232-229-57.compute-1.amazonaws.com\",\"publicIp\":\"3.232.229.57\"},\"primary\":true,\"privateDnsName\":\"ip-172-31-78-41.ec2.internal\",\"privateIpAddress\":\"172.31.78.41\"}],\"sourceDestCheck\":true,\"status\":\"in-use\",\"subnetId\":\"subnet-cad1f2f4\",\"vpcId\":\"vpc-2d96be57\",\"interfaceType\":\"interface\"},{\"association\":null,\"attachment\":{\"attachTime\":\"2020-11-26T23:46:04.000Z\",\"attachmentId\":\"eni-attach-0e6d150ebbd19966e\",\"deleteOnTermination\":false,\"deviceIndex\":1,\"status\":\"attached\",\"networkCardIndex\":0},\"description\":\"MINHAEC2AAAAAA\",\"groups\":[{\"groupName\":\"minhaec2\",\"groupId\":\"sg-0fb295a327d9b4835\"},{\"groupName\":\"default\",\"groupId\":\"sg-88105fa0\"}],\"ipv6Addresses\":[],\"macAddress\":\"06:0a:62:00:64:5f\",\"networkInterfaceId\":\"eni-09a604c0ec356b06f\",\"ownerId\":\"200984112386\",\"privateDnsName\":\"ip-172-31-70-9.ec2.internal\",\"privateIpAddress\":\"172.31.70.9\",\"privateIpAddresses\":[{\"association\":null,\"primary\":true,\"privateDnsName\":\"ip-172-31-70-9.ec2.internal\",\"privateIpAddress\":\"172.31.70.9\"}],\"sourceDestCheck\":true,\"status\":\"in-use\",\"subnetId\":\"subnet-cad1f2f4\",\"vpcId\":\"vpc-2d96be57\",\"interfaceType\":\"interface\"}],\"outpostArn\":null,\"rootDeviceName\":\"/dev/xvda\",\"rootDeviceType\":\"ebs\",\"securityGroups\":[{\"groupName\":\"minhaec2\",\"groupId\":\"sg-0fb295a327d9b4835\"}],\"sourceDestCheck\":true,\"spotInstanceRequestId\":null,\"sriovNetSupport\":null,\"stateReason\":{\"code\":\"Client.UserInitiatedShutdown\",\"message\":\"Client.UserInitiatedShutdown: User initiated shutdown\"},\"tags\":[{\"key\":\"projeto\",\"value\":\"meetup\"},{\"key\":\"Name\",\"value\":\"Minha\"},{\"key\":\"CentroCusto\",\"value\":\"TI\"},{\"key\":\"Setor\",\"value\":\"Desenvolvimento\"}],\"virtualizationType\":\"hvm\",\"cpuOptions\":{\"coreCount\":2,\"threadsPerCore\":1},\"capacityReservationId\":null,\"capacityReservationSpecification\":{\"capacityReservationPreference\":\"open\",\"capacityReservationTarget\":null},\"hibernationOptions\":{\"configured\":false},\"licenses\":[],\"metadataOptions\":{\"state\":\"applied\",\"httpTokens\":\"optional\",\"httpPutResponseHopLimit\":1,\"httpEndpoint\":\"enabled\"},\"enclaveOptions\":{\"enabled\":false},\"bootMode\":null},\"supplementaryConfiguration\":{},\"tags\":{\"projeto\":\"meetup\",\"Setor\":\"Desenvolvimento\",\"CentroCusto\":\"TI\",\"Name\":\"Minha\"},\"configurationItemVersion\":\"1.3\",\"configurationItemCaptureTime\":\"2023-04-27T15:03:11.636Z\",\"configurationStateId\":1682607791636,\"awsAccountId\":\"200984112386\",\"configurationItemStatus\":\"OK\",\"resourceType\":\"AWS::EC2::Instance\",\"resourceId\":\"i-042dd005362091826\",\"resourceName\":null,\"ARN\":\"arn:aws:ec2:us-east-1:200984112386:instance/i-042dd005362091826\",\"awsRegion\":\"us-east-1\",\"availabilityZone\":\"us-east-1e\",\"configurationStateMd5Hash\":\"\",\"resourceCreationTime\":\"2023-04-27T14:57:16.000Z\"},\"notificationCreationTime\":\"2023-04-27T15:03:13.332Z\",\"messageType\":\"ConfigurationItemChangeNotification\",\"recordVersion\":\"1.3\"}", + "invokingEvent":"{\"configurationItemDiff\":{\"changedProperties\":{\"Configuration.InstanceType\":{\"previousValue\":\"t2.micro\",\"updatedValue\":\"t2.medium\",\"changeType\":\"UPDATE\"},\"Configuration.State.Name\":{\"previousValue\":\"running\",\"updatedValue\":\"stopped\",\"changeType\":\"UPDATE\"},\"Configuration.StateTransitionReason\":{\"previousValue\":\"\",\"updatedValue\":\"User initiated (2023-04-27 15:01:07 GMT)\",\"changeType\":\"UPDATE\"},\"Configuration.StateReason\":{\"previousValue\":null,\"updatedValue\":{\"code\":\"Client.UserInitiatedShutdown\",\"message\":\"Client.UserInitiatedShutdown: User initiated shutdown\"},\"changeType\":\"CREATE\"},\"Configuration.CpuOptions.CoreCount\":{\"previousValue\":1,\"updatedValue\":2,\"changeType\":\"UPDATE\"}},\"changeType\":\"UPDATE\"},\"configurationItem\":{\"relatedEvents\":[],\"relationships\":[{\"resourceId\":\"eipalloc-0ebb4367662263cc1\",\"resourceName\":null,\"resourceType\":\"AWS::EC2::EIP\",\"name\":\"Is attached to ElasticIp\"},{\"resourceId\":\"eni-034dd31c4b17ada8c\",\"resourceName\":null,\"resourceType\":\"AWS::EC2::NetworkInterface\",\"name\":\"Contains NetworkInterface\"},{\"resourceId\":\"eni-09a604c0ec356b06f\",\"resourceName\":null,\"resourceType\":\"AWS::EC2::NetworkInterface\",\"name\":\"Contains NetworkInterface\"},{\"resourceId\":\"sg-0fb295a327d9b4835\",\"resourceName\":null,\"resourceType\":\"AWS::EC2::SecurityGroup\",\"name\":\"Is associated with SecurityGroup\"},{\"resourceId\":\"subnet-cad1f2f4\",\"resourceName\":null,\"resourceType\":\"AWS::EC2::Subnet\",\"name\":\"Is contained in Subnet\"},{\"resourceId\":\"vol-0a288b5eb9fea4b30\",\"resourceName\":null,\"resourceType\":\"AWS::EC2::Volume\",\"name\":\"Is attached to Volume\"},{\"resourceId\":\"vpc-2d96be57\",\"resourceName\":null,\"resourceType\":\"AWS::EC2::VPC\",\"name\":\"Is contained in Vpc\"}],\"configuration\":{\"amiLaunchIndex\":0,\"imageId\":\"ami-09d95fab7fff3776c\",\"instanceId\":\"i-042dd005362091826\",\"instanceType\":\"t2.medium\",\"kernelId\":null,\"keyName\":\"mihaec2\",\"launchTime\":\"2023-04-27T14:57:16.000Z\",\"monitoring\":{\"state\":\"disabled\"},\"placement\":{\"availabilityZone\":\"us-east-1e\",\"affinity\":null,\"groupName\":\"\",\"partitionNumber\":null,\"hostId\":null,\"tenancy\":\"default\",\"spreadDomain\":null,\"hostResourceGroupArn\":null},\"platform\":null,\"privateDnsName\":\"ip-172-31-78-41.ec2.internal\",\"privateIpAddress\":\"172.31.78.41\",\"productCodes\":[],\"publicDnsName\":\"ec2-3-232-229-57.compute-1.amazonaws.com\",\"publicIpAddress\":\"3.232.229.57\",\"ramdiskId\":null,\"state\":{\"code\":80,\"name\":\"stopped\"},\"stateTransitionReason\":\"User initiated (2023-04-27 15:01:07 GMT)\",\"subnetId\":\"subnet-cad1f2f4\",\"vpcId\":\"vpc-2d96be57\",\"architecture\":\"x86_64\",\"blockDeviceMappings\":[{\"deviceName\":\"/dev/xvda\",\"ebs\":{\"attachTime\":\"2020-05-30T15:21:58.000Z\",\"deleteOnTermination\":true,\"status\":\"attached\",\"volumeId\":\"vol-0a288b5eb9fea4b30\"}}],\"clientToken\":\"\",\"ebsOptimized\":false,\"enaSupport\":true,\"hypervisor\":\"xen\",\"iamInstanceProfile\":{\"arn\":\"arn:aws:iam::0123456789012:instance-profile/AmazonSSMRoleForInstancesQuickSetup\",\"id\":\"AIPAS5S4WFUBL72S3QXW5\"},\"instanceLifecycle\":null,\"elasticGpuAssociations\":[],\"elasticInferenceAcceleratorAssociations\":[],\"networkInterfaces\":[{\"association\":{\"carrierIp\":null,\"ipOwnerId\":\"0123456789012\",\"publicDnsName\":\"ec2-3-232-229-57.compute-1.amazonaws.com\",\"publicIp\":\"3.232.229.57\"},\"attachment\":{\"attachTime\":\"2020-05-30T15:21:57.000Z\",\"attachmentId\":\"eni-attach-0a7e75dc9c1c291a0\",\"deleteOnTermination\":true,\"deviceIndex\":0,\"status\":\"attached\",\"networkCardIndex\":0},\"description\":\"\",\"groups\":[{\"groupName\":\"minhaec2\",\"groupId\":\"sg-0fb295a327d9b4835\"}],\"ipv6Addresses\":[],\"macAddress\":\"06:cf:00:c2:17:db\",\"networkInterfaceId\":\"eni-034dd31c4b17ada8c\",\"ownerId\":\"0123456789012\",\"privateDnsName\":\"ip-172-31-78-41.ec2.internal\",\"privateIpAddress\":\"172.31.78.41\",\"privateIpAddresses\":[{\"association\":{\"carrierIp\":null,\"ipOwnerId\":\"0123456789012\",\"publicDnsName\":\"ec2-3-232-229-57.compute-1.amazonaws.com\",\"publicIp\":\"3.232.229.57\"},\"primary\":true,\"privateDnsName\":\"ip-172-31-78-41.ec2.internal\",\"privateIpAddress\":\"172.31.78.41\"}],\"sourceDestCheck\":true,\"status\":\"in-use\",\"subnetId\":\"subnet-cad1f2f4\",\"vpcId\":\"vpc-2d96be57\",\"interfaceType\":\"interface\"},{\"association\":null,\"attachment\":{\"attachTime\":\"2020-11-26T23:46:04.000Z\",\"attachmentId\":\"eni-attach-0e6d150ebbd19966e\",\"deleteOnTermination\":false,\"deviceIndex\":1,\"status\":\"attached\",\"networkCardIndex\":0},\"description\":\"MINHAEC2AAAAAA\",\"groups\":[{\"groupName\":\"minhaec2\",\"groupId\":\"sg-0fb295a327d9b4835\"},{\"groupName\":\"default\",\"groupId\":\"sg-88105fa0\"}],\"ipv6Addresses\":[],\"macAddress\":\"06:0a:62:00:64:5f\",\"networkInterfaceId\":\"eni-09a604c0ec356b06f\",\"ownerId\":\"0123456789012\",\"privateDnsName\":\"ip-172-31-70-9.ec2.internal\",\"privateIpAddress\":\"172.31.70.9\",\"privateIpAddresses\":[{\"association\":null,\"primary\":true,\"privateDnsName\":\"ip-172-31-70-9.ec2.internal\",\"privateIpAddress\":\"172.31.70.9\"}],\"sourceDestCheck\":true,\"status\":\"in-use\",\"subnetId\":\"subnet-cad1f2f4\",\"vpcId\":\"vpc-2d96be57\",\"interfaceType\":\"interface\"}],\"outpostArn\":null,\"rootDeviceName\":\"/dev/xvda\",\"rootDeviceType\":\"ebs\",\"securityGroups\":[{\"groupName\":\"minhaec2\",\"groupId\":\"sg-0fb295a327d9b4835\"}],\"sourceDestCheck\":true,\"spotInstanceRequestId\":null,\"sriovNetSupport\":null,\"stateReason\":{\"code\":\"Client.UserInitiatedShutdown\",\"message\":\"Client.UserInitiatedShutdown: User initiated shutdown\"},\"tags\":[{\"key\":\"projeto\",\"value\":\"meetup\"},{\"key\":\"Name\",\"value\":\"Minha\"},{\"key\":\"CentroCusto\",\"value\":\"TI\"},{\"key\":\"Setor\",\"value\":\"Desenvolvimento\"}],\"virtualizationType\":\"hvm\",\"cpuOptions\":{\"coreCount\":2,\"threadsPerCore\":1},\"capacityReservationId\":null,\"capacityReservationSpecification\":{\"capacityReservationPreference\":\"open\",\"capacityReservationTarget\":null},\"hibernationOptions\":{\"configured\":false},\"licenses\":[],\"metadataOptions\":{\"state\":\"applied\",\"httpTokens\":\"optional\",\"httpPutResponseHopLimit\":1,\"httpEndpoint\":\"enabled\"},\"enclaveOptions\":{\"enabled\":false},\"bootMode\":null},\"supplementaryConfiguration\":{},\"tags\":{\"projeto\":\"meetup\",\"Setor\":\"Desenvolvimento\",\"CentroCusto\":\"TI\",\"Name\":\"Minha\"},\"configurationItemVersion\":\"1.3\",\"configurationItemCaptureTime\":\"2023-04-27T15:03:11.636Z\",\"configurationStateId\":1682607791636,\"awsAccountId\":\"0123456789012\",\"configurationItemStatus\":\"OK\",\"resourceType\":\"AWS::EC2::Instance\",\"resourceId\":\"i-042dd005362091826\",\"resourceName\":null,\"ARN\":\"arn:aws:ec2:us-east-1:0123456789012:instance/i-042dd005362091826\",\"awsRegion\":\"us-east-1\",\"availabilityZone\":\"us-east-1e\",\"configurationStateMd5Hash\":\"\",\"resourceCreationTime\":\"2023-04-27T14:57:16.000Z\"},\"notificationCreationTime\":\"2023-04-27T15:03:13.332Z\",\"messageType\":\"ConfigurationItemChangeNotification\",\"recordVersion\":\"1.3\"}", "ruleParameters":"{\"desiredInstanceType\": \"t2.micro\"}", "resultToken":"eyJlbmNyeXB0ZWREYXRhIjpbLTQxLDEsLTU3LC0zMCwtMTIxLDUzLDUyLDQ1LC01NywtOCw3MywtODEsLTExNiwtMTAyLC01MiwxMTIsLTQ3LDU4LDY1LC0xMjcsMTAyLDUsLTY5LDQ0LC0xNSwxMTQsNDEsLTksMTExLC0zMCw2NSwtNzUsLTM1LDU0LDEwNSwtODksODYsNDAsLTEwNSw5OCw2NSwtMTE5LC02OSwyNCw2NiwtMjAsODAsLTExMiwtNzgsLTgwLDQzLC01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ws:iam::200984112386:role/aws-service-role/config.amazonaws.com/AWSServiceRoleForConfig", - "configRuleArn":"arn:aws:config:us-east-1:200984112386:config-rule/config-rule-i9y8j9", + "executionRoleArn":"arn:aws:iam::0123456789012:role/aws-service-role/config.amazonaws.com/AWSServiceRoleForConfig", + "configRuleArn":"arn:aws:config:us-east-1:0123456789012:config-rule/config-rule-i9y8j9", "configRuleName":"MyRule", "configRuleId":"config-rule-i9y8j9", - "accountId":"200984112386", + "accountId":"0123456789012", "evaluationMode":"DETECTIVE" } diff --git a/examples/event_sources/src/aws_config_rule_scheduled.json b/examples/event_sources/src/aws_config_rule_scheduled.json index 33e857fbab2..f21ed9fe57f 100644 --- a/examples/event_sources/src/aws_config_rule_scheduled.json +++ b/examples/event_sources/src/aws_config_rule_scheduled.json @@ -1,13 +1,13 @@ { "version":"1.0", - "invokingEvent":"{\"awsAccountId\":\"200984112386\",\"notificationCreationTime\":\"2023-04-27T13:26:17.741Z\",\"messageType\":\"ScheduledNxotification\",\"recordVersion\":\"1.0\"}", + "invokingEvent":"{\"awsAccountId\":\"0123456789012\",\"notificationCreationTime\":\"2023-04-27T13:26:17.741Z\",\"messageType\":\"ScheduledNxotification\",\"recordVersion\":\"1.0\"}", "ruleParameters":"{\"test\":\"x\"}", "resultToken":"eyJlbmNyeXB0ZWREYXRhIjpbLTQyLDEyNiw1MiwtMzcsLTI5LDExNCwxMjYsLTk3LDcxLDIyLC0xMTAsMTEyLC0zMSwtOTMsLTQ5LC0xMDEsODIsMyw1NCw0OSwzLC02OSwtNzEsLTcyLDYyLDgxLC03MiwtODEsNTAsMzUsLTUwLC03NSwtMTE4LC0xMTgsNzcsMTIsLTEsMTQsMTIwLC03MCwxMTAsLTMsNTAsLTYwLDEwNSwtNTcsNDUsMTAyLC0xMDksLTYxLC0xMDEsLTYxLDQsNDcsLTg0LC0yNSwxMTIsNTQsLTcxLC0xMDksNDUsMTksMTIzLC0yNiwxMiwtOTYsLTczLDU0LC0xMDksOTIsNDgsLTU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MiwxMTYsLTk5LC00NSwxMDAsLTM1LDg3LDM3LDYsOTgsMiwxMTIsNjAsLTMzLDE3LDI2LDk5LC0xMDUsNDgsLTEwNCwtMTE5LDc4LDYsLTU4LDk1LDksNDEsLTE2LDk2LDQxLC0yMiw5Niw3MiwxMTYsLTk1LC0xMDUsLTM2LC0xMjMsLTU1LDkxLC00NiwtNywtOTIsMzksNDUsODQsMTYsLTEyNCwtMTIyLC02OCwxLC0yOCwxMjIsLTYwLDgyLDEwMywtNTQsLTkyLDI3LC05OSwtMTI4LDY1LDcsLTcyLC0xMjcsNjIsLTIyLDIsLTExLDE4LC04OSwtMTA2LC03NCw3MSw4NiwtMTE2LC0yNSwtMTE1LC05Niw1NywtMzQsMjIsLTEyNCwtMTI1LC00LC00MSw0MiwtNTcsLTEwMyw0NSw3OCwxNCwtMTA2LDExMSw5OCwtOTQsLTcxLDUsNzUsMTksLTEyNCwtMzAsMzQsLTUwLDc1LC04NCwtNTAsLTU2LDUxLC0xNSwtMzYsNjEsLTk0LC03OSwtNDUsMTI2LC03NywtMTA1LC0yLC05MywtNiw4LC0zLDYsLTQyLDQ2LDEyNSw1LC05OCwxMyw2NywtMTAsLTEzLC05NCwtNzgsLTEyNywxMjEsLTI2LC04LC0xMDEsLTkxLDEyMSwtNDAsLTEyNCwtNjQsODQsLTcyLDYzLDE5LC04NF0sIm1hdGVyaWFsU2V0U2VyaWFsTnVtYmVyIjoxLCJpdlBhcmFtZXRlclNwZWMiOnsiaXYiOlszLC0xMCwtODUsMTE0LC05MCwxMTUsNzcsNTUsNTQsMTUsMzgsODQsLTExNiwxNCwtNDAsMjhdfX0=", "eventLeftScope":false, - "executionRoleArn":"arn:aws:iam::200984112386:role/aws-service-role/config.amazonaws.com/AWSServiceRoleForConfig", - "configRuleArn":"arn:aws:config:us-east-1:200984112386:config-rule/config-rule-pdmyw1", + "executionRoleArn":"arn:aws:iam::0123456789012:role/aws-service-role/config.amazonaws.com/AWSServiceRoleForConfig", + "configRuleArn":"arn:aws:config:us-east-1:0123456789012:config-rule/config-rule-pdmyw1", "configRuleName":"rule-ec2-test", "configRuleId":"config-rule-pdmyw1", - "accountId":"200984112386", + "accountId":"0123456789012", "evaluationMode":"DETECTIVE" } diff --git a/tests/functional/test_data_classes.py b/tests/functional/test_data_classes.py index 8146860ea8c..89414f9ba79 100644 --- a/tests/functional/test_data_classes.py +++ b/tests/functional/test_data_classes.py @@ -2001,7 +2001,7 @@ def test_api_gateway_route_arn_parser(): def test_aws_config_rule_configuration_changed(): - """Check API Gateway authorizer token event""" + """Check AWS Config ConfigurationItemChangeNotification event""" event = AWSConfigRuleEvent(load_event("awsConfigRuleConfigurationChanged.json")) invoking_event = json.loads(event["invokingEvent"]) @@ -2016,7 +2016,7 @@ def test_aws_config_rule_configuration_changed(): def test_aws_config_rule_oversized_configuration(): - """Check API Gateway authorizer token event""" + """Check AWS Config OversizedConfigurationItemChangeNotification event""" event = AWSConfigRuleEvent(load_event("awsConfigRuleOversizedConfiguration.json")) invoking_event = json.loads(event["invokingEvent"]) @@ -2030,8 +2030,8 @@ def test_aws_config_rule_oversized_configuration(): def test_aws_config_rule_scheduled(): - """Check API Gateway authorizer token event""" - event = AWSConfigRuleEvent(load_event("awsConfigRuleOversizedConfiguration.json")) + """Check AWS Config ScheduledNotification event""" + event = AWSConfigRuleEvent(load_event("awsConfigRuleScheduled.json")) invoking_event = json.loads(event["invokingEvent"]) From 0797c2c5c07247a9432099de3fb9864ccc0a0be7 Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Fri, 28 Apr 2023 01:34:52 +0100 Subject: [PATCH 07/14] feat(dataclass): improving code coverage --- tests/events/awsConfigRuleScheduled.json | 2 +- tests/functional/test_data_classes.py | 38 ++++++++++++++++++++---- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/tests/events/awsConfigRuleScheduled.json b/tests/events/awsConfigRuleScheduled.json index f21ed9fe57f..02ce2a0700c 100644 --- a/tests/events/awsConfigRuleScheduled.json +++ b/tests/events/awsConfigRuleScheduled.json @@ -1,6 +1,6 @@ { "version":"1.0", - "invokingEvent":"{\"awsAccountId\":\"0123456789012\",\"notificationCreationTime\":\"2023-04-27T13:26:17.741Z\",\"messageType\":\"ScheduledNxotification\",\"recordVersion\":\"1.0\"}", + "invokingEvent":"{\"awsAccountId\":\"0123456789012\",\"notificationCreationTime\":\"2023-04-27T13:26:17.741Z\",\"messageType\":\"ScheduledNotification\",\"recordVersion\":\"1.0\"}", "ruleParameters":"{\"test\":\"x\"}", "resultToken":"eyJlbmNyeXB0ZWREYXRhIjpbLTQyLDEyNiw1MiwtMzcsLTI5LDExNCwxMjYsLTk3LDcxLDIyLC0xMTAsMTEyLC0zMSwtOTMsLTQ5LC0xMDEsODIsMyw1NCw0OSwzLC02OSwtNzEsLTcyLDYyLDgxLC03MiwtODEsNTAsMzUsLTUwLC03NSwtMTE4LC0xMTgsNzcsMTIsLTEsMTQsMTIwLC03MCwxMTAsLTMsNTAsLTYwLDEwNSwtNTcsNDUsMTAyLC0xMDksLTYxLC0xMDEsLTYxLDQsNDcsLTg0LC0yNSwxMTIsNTQsLTcxLC0xMDksNDUsMTksMTIzLC0yNiwxMiwtOTYsLTczLDU0LC0xMDksOTIsNDgsLTU5LC04MywtMzIsODIsLTM2LC05MCwxOSw5OCw3Nyw3OCw0MCw4MCw3OCwtMTA1LDg3LC0xMTMsLTExNiwtNzIsMzAsLTY4LC00MCwtODksMTA5LC0xMDgsLTEyOCwyMiw3Miw3NywtMjEsNzYsODksOTQsLTU5LDgxLC0xMjEsLTEwNywtNjcsNjMsLTcsODIsLTg5LC00NiwtMzQsLTkyLDEyMiwtOTAsMTcsLTEyMywyMCwtODUsLTU5LC03MCw4MSwyNyw2Miw3NCwtODAsODAsMzcsNDAsMTE2LDkxLC0yNCw1MSwtNDEsLTc5LDI4LDEyMCw1MywtMTIyLC04MywxMjYsLTc4LDI1LC05OCwtMzYsMTMsMzIsODYsLTI1LDQ4LDMsLTEwMiwtMTYsMjQsLTMsOD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00LC00MSw0MiwtNTcsLTEwMyw0NSw3OCwxNCwtMTA2LDExMSw5OCwtOTQsLTcxLDUsNzUsMTksLTEyNCwtMzAsMzQsLTUwLDc1LC04NCwtNTAsLTU2LDUxLC0xNSwtMzYsNjEsLTk0LC03OSwtNDUsMTI2LC03NywtMTA1LC0yLC05MywtNiw4LC0zLDYsLTQyLDQ2LDEyNSw1LC05OCwxMyw2NywtMTAsLTEzLC05NCwtNzgsLTEyNywxMjEsLTI2LC04LC0xMDEsLTkxLDEyMSwtNDAsLTEyNCwtNjQsODQsLTcyLDYzLDE5LC04NF0sIm1hdGVyaWFsU2V0U2VyaWFsTnVtYmVyIjoxLCJpdlBhcmFtZXRlclNwZWMiOnsiaXYiOlszLC0xMCwtODUsMTE0LC05MCwxMTUsNzcsNTUsNTQsMTUsMzgsODQsLTExNiwxNCwtNDAsMjhdfX0=", "eventLeftScope":false, diff --git a/tests/functional/test_data_classes.py b/tests/functional/test_data_classes.py index 89414f9ba79..4d86974e6ec 100644 --- a/tests/functional/test_data_classes.py +++ b/tests/functional/test_data_classes.py @@ -2006,10 +2006,18 @@ def test_aws_config_rule_configuration_changed(): invoking_event = json.loads(event["invokingEvent"]) - assert event.invoking_event.message_type == invoking_event["messageType"] + assert event.rule_parameters == json.loads(event["ruleParameters"]) + assert event.raw_invoking_event == event["invokingEvent"] + assert event.result_token == event["resultToken"] + assert event.event_left_scope == event["eventLeftScope"] + assert event.execution_role_arn == event["executionRoleArn"] + assert event.config_rule_arn == event["configRuleArn"] + assert event.config_rule_id == event["configRuleId"] + assert event.config_rule_arn == event["configRuleArn"] assert event.accountid == event["accountId"] assert event.version == event["version"] - assert event.execution_role_arn == event["executionRoleArn"] + assert event.invoking_event.message_type == invoking_event["messageType"] + assert hasattr(event.invoking_event, "configuration_item_diff") assert hasattr(event.invoking_event, "configuration_item") assert hasattr(event.invoking_event.configuration_item, "configuration") @@ -2021,10 +2029,17 @@ def test_aws_config_rule_oversized_configuration(): invoking_event = json.loads(event["invokingEvent"]) - assert event.invoking_event.message_type == invoking_event["messageType"] + assert event.rule_parameters == json.loads(event["ruleParameters"]) + assert event.raw_invoking_event == event["invokingEvent"] + assert event.result_token == event["resultToken"] + assert event.event_left_scope == event["eventLeftScope"] + assert event.execution_role_arn == event["executionRoleArn"] + assert event.config_rule_arn == event["configRuleArn"] + assert event.config_rule_id == event["configRuleId"] + assert event.config_rule_arn == event["configRuleArn"] assert event.accountid == event["accountId"] assert event.version == event["version"] - assert event.execution_role_arn == event["executionRoleArn"] + assert event.invoking_event.message_type == invoking_event["messageType"] assert hasattr(event.invoking_event, "configuration_item_summary") assert hasattr(event.invoking_event.configuration_item_summary, "change_type") @@ -2035,7 +2050,18 @@ def test_aws_config_rule_scheduled(): invoking_event = json.loads(event["invokingEvent"]) - assert event.invoking_event.message_type == invoking_event["messageType"] + assert event.rule_parameters == json.loads(event["ruleParameters"]) + assert event.raw_invoking_event == event["invokingEvent"] + assert event.result_token == event["resultToken"] + assert event.event_left_scope == event["eventLeftScope"] + assert event.execution_role_arn == event["executionRoleArn"] + assert event.config_rule_arn == event["configRuleArn"] + assert event.config_rule_id == event["configRuleId"] + assert event.config_rule_arn == event["configRuleArn"] assert event.accountid == event["accountId"] assert event.version == event["version"] - assert event.execution_role_arn == event["executionRoleArn"] + assert event.invoking_event.message_type == invoking_event["messageType"] + assert event.invoking_event.accountid == invoking_event["awsAccountId"] + assert event.invoking_event.notification_creation_time == invoking_event["notificationCreationTime"] + assert event.invoking_event.message_type == invoking_event["messageType"] + assert event.invoking_event.record_version == invoking_event["recordVersion"] From c9cd24b29875d54919bec73e055f907296d0ef1d Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Fri, 28 Apr 2023 01:50:29 +0100 Subject: [PATCH 08/14] feat(dataclass): adding fields to test class --- .../data_classes/aws_config_rule_event.py | 6 +- tests/functional/test_data_classes.py | 64 +++++++++++++++++-- 2 files changed, 62 insertions(+), 8 deletions(-) diff --git a/aws_lambda_powertools/utilities/data_classes/aws_config_rule_event.py b/aws_lambda_powertools/utilities/data_classes/aws_config_rule_event.py index 2a1a5965d05..f1498839861 100644 --- a/aws_lambda_powertools/utilities/data_classes/aws_config_rule_event.py +++ b/aws_lambda_powertools/utilities/data_classes/aws_config_rule_event.py @@ -1,7 +1,7 @@ from __future__ import annotations import json -from typing import Dict, List +from typing import Dict, List, Optional from aws_lambda_powertools.utilities.data_classes.common import DictWrapper @@ -330,6 +330,6 @@ def accountid(self) -> str: return self["accountId"] @property - def evalution_mode(self) -> str: + def evalution_mode(self) -> Optional[str]: """The evalution mode of the event.""" - return self["evaluationMode"] + return self.get("evaluationMode") diff --git a/tests/functional/test_data_classes.py b/tests/functional/test_data_classes.py index 4d86974e6ec..c9eff13f746 100644 --- a/tests/functional/test_data_classes.py +++ b/tests/functional/test_data_classes.py @@ -2013,9 +2013,9 @@ def test_aws_config_rule_configuration_changed(): assert event.execution_role_arn == event["executionRoleArn"] assert event.config_rule_arn == event["configRuleArn"] assert event.config_rule_id == event["configRuleId"] - assert event.config_rule_arn == event["configRuleArn"] assert event.accountid == event["accountId"] assert event.version == event["version"] + assert event.evalution_mode == event["evaluationMode"] assert event.invoking_event.message_type == invoking_event["messageType"] assert hasattr(event.invoking_event, "configuration_item_diff") @@ -2036,12 +2036,66 @@ def test_aws_config_rule_oversized_configuration(): assert event.execution_role_arn == event["executionRoleArn"] assert event.config_rule_arn == event["configRuleArn"] assert event.config_rule_id == event["configRuleId"] - assert event.config_rule_arn == event["configRuleArn"] assert event.accountid == event["accountId"] assert event.version == event["version"] assert event.invoking_event.message_type == invoking_event["messageType"] - assert hasattr(event.invoking_event, "configuration_item_summary") - assert hasattr(event.invoking_event.configuration_item_summary, "change_type") + assert event.invoking_event.raw_configuration_item_summary == invoking_event["configurationItemSummary"] + assert ( + event.invoking_event.configuration_item_summary.change_type + == invoking_event["configurationItemSummary"]["changeType"] + ) + assert ( + event.invoking_event.configuration_item_summary.configuration_item_version + == invoking_event["configurationItemSummary"]["configurationItemVersion"] + ) + assert ( + event.invoking_event.configuration_item_summary.configuration_item_capture_time + == invoking_event["configurationItemSummary"]["configurationItemCaptureTime"] + ) + assert ( + event.invoking_event.configuration_item_summary.configuration_state_id + == invoking_event["configurationItemSummary"]["configurationStateId"] + ) + assert ( + event.invoking_event.configuration_item_summary.accountid + == invoking_event["configurationItemSummary"]["awsAccountId"] + ) + assert ( + event.invoking_event.configuration_item_summary.configuration_item_status + == invoking_event["configurationItemSummary"]["configurationItemStatus"] + ) + assert ( + event.invoking_event.configuration_item_summary.resource_type + == invoking_event["configurationItemSummary"]["resourceType"] + ) + assert ( + event.invoking_event.configuration_item_summary.resource_id + == invoking_event["configurationItemSummary"]["resourceId"] + ) + assert ( + event.invoking_event.configuration_item_summary.resource_name + == invoking_event["configurationItemSummary"]["resourceName"] + ) + assert ( + event.invoking_event.configuration_item_summary.resource_arn + == invoking_event["configurationItemSummary"]["ARN"] + ) + assert ( + event.invoking_event.configuration_item_summary.region + == invoking_event["configurationItemSummary"]["awsRegion"] + ) + assert ( + event.invoking_event.configuration_item_summary.availability_zone + == invoking_event["configurationItemSummary"]["availabilityZone"] + ) + assert ( + event.invoking_event.configuration_item_summary.configuration_state_md5_hash + == invoking_event["configurationItemSummary"]["configurationStateMd5Hash"] + ) + assert ( + event.invoking_event.configuration_item_summary.resource_creation_time + == invoking_event["configurationItemSummary"]["resourceCreationTime"] + ) def test_aws_config_rule_scheduled(): @@ -2057,9 +2111,9 @@ def test_aws_config_rule_scheduled(): assert event.execution_role_arn == event["executionRoleArn"] assert event.config_rule_arn == event["configRuleArn"] assert event.config_rule_id == event["configRuleId"] - assert event.config_rule_arn == event["configRuleArn"] assert event.accountid == event["accountId"] assert event.version == event["version"] + assert event.evalution_mode == event["evaluationMode"] assert event.invoking_event.message_type == invoking_event["messageType"] assert event.invoking_event.accountid == invoking_event["awsAccountId"] assert event.invoking_event.notification_creation_time == invoking_event["notificationCreationTime"] From 5bd9808f5324552a78085f422adb47ccc9e3366a Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Fri, 28 Apr 2023 02:25:19 +0100 Subject: [PATCH 09/14] feat(dataclass): more fields --- .../data_classes/aws_config_rule_event.py | 5 +- tests/functional/test_data_classes.py | 57 +++++++++++++++++-- 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/aws_lambda_powertools/utilities/data_classes/aws_config_rule_event.py b/aws_lambda_powertools/utilities/data_classes/aws_config_rule_event.py index f1498839861..71e52d98b5b 100644 --- a/aws_lambda_powertools/utilities/data_classes/aws_config_rule_event.py +++ b/aws_lambda_powertools/utilities/data_classes/aws_config_rule_event.py @@ -32,8 +32,9 @@ def configuration_item(self) -> AWSConfigConfigurationItemChanged: """The configuration item of the ConfigurationItemChangeNotification event.""" return AWSConfigConfigurationItemChanged(self["configurationItem"]) + @property def raw_configuration_item(self) -> Dict: - """The raw configuration item diff of the ConfigurationItemChangeNotification event.""" + """The raw configuration item of the ConfigurationItemChangeNotification event.""" return self["configurationItem"] @property @@ -317,7 +318,7 @@ def config_rule_arn(self) -> str: @property def config_rule_name(self) -> str: """The name of the rule of the event.""" - return self["configRuleArn"] + return self["configRuleName"] @property def config_rule_id(self) -> str: diff --git a/tests/functional/test_data_classes.py b/tests/functional/test_data_classes.py index c9eff13f746..661a5923c9f 100644 --- a/tests/functional/test_data_classes.py +++ b/tests/functional/test_data_classes.py @@ -2012,15 +2012,60 @@ def test_aws_config_rule_configuration_changed(): assert event.event_left_scope == event["eventLeftScope"] assert event.execution_role_arn == event["executionRoleArn"] assert event.config_rule_arn == event["configRuleArn"] + assert event.config_rule_name == event["configRuleName"] assert event.config_rule_id == event["configRuleId"] assert event.accountid == event["accountId"] assert event.version == event["version"] assert event.evalution_mode == event["evaluationMode"] assert event.invoking_event.message_type == invoking_event["messageType"] - - assert hasattr(event.invoking_event, "configuration_item_diff") - assert hasattr(event.invoking_event, "configuration_item") - assert hasattr(event.invoking_event.configuration_item, "configuration") + assert event.invoking_event.raw_configuration_item == invoking_event["configurationItem"] + assert event.invoking_event.record_version == invoking_event["recordVersion"] + assert event.invoking_event.notification_creation_time == invoking_event["notificationCreationTime"] + assert event.invoking_event.configuration_item_diff == invoking_event["configurationItemDiff"] + assert ( + event.invoking_event.configuration_item.related_events == invoking_event["configurationItem"]["relatedEvents"] + ) + assert event.invoking_event.configuration_item.relationships == invoking_event["configurationItem"]["relationships"] + assert event.invoking_event.configuration_item.configuration == invoking_event["configurationItem"]["configuration"] + assert ( + event.invoking_event.configuration_item.supplementary_configuration + == invoking_event["configurationItem"]["supplementaryConfiguration"] + ) + assert event.invoking_event.configuration_item.tags == invoking_event["configurationItem"]["tags"] + assert ( + event.invoking_event.configuration_item.configuration_item_version + == invoking_event["configurationItem"]["configurationItemVersion"] + ) + assert ( + event.invoking_event.configuration_item.configuration_item_capture_time + == invoking_event["configurationItem"]["configurationItemCaptureTime"] + ) + assert ( + event.invoking_event.configuration_item.configuration_state_id + == invoking_event["configurationItem"]["configurationStateId"] + ) + assert event.invoking_event.configuration_item.accountid == invoking_event["configurationItem"]["awsAccountId"] + assert ( + event.invoking_event.configuration_item.configuration_item_status + == invoking_event["configurationItem"]["configurationItemStatus"] + ) + assert event.invoking_event.configuration_item.resource_type == invoking_event["configurationItem"]["resourceType"] + assert event.invoking_event.configuration_item.resource_id == invoking_event["configurationItem"]["resourceId"] + assert event.invoking_event.configuration_item.resource_name == invoking_event["configurationItem"]["resourceName"] + assert event.invoking_event.configuration_item.resource_arn == invoking_event["configurationItem"]["ARN"] + assert event.invoking_event.configuration_item.region == invoking_event["configurationItem"]["awsRegion"] + assert ( + event.invoking_event.configuration_item.availability_zone + == invoking_event["configurationItem"]["availabilityZone"] + ) + assert ( + event.invoking_event.configuration_item.configuration_state_md5_hash + == invoking_event["configurationItem"]["configurationStateMd5Hash"] + ) + assert ( + event.invoking_event.configuration_item.resource_creation_time + == invoking_event["configurationItem"]["resourceCreationTime"] + ) def test_aws_config_rule_oversized_configuration(): @@ -2035,10 +2080,13 @@ def test_aws_config_rule_oversized_configuration(): assert event.event_left_scope == event["eventLeftScope"] assert event.execution_role_arn == event["executionRoleArn"] assert event.config_rule_arn == event["configRuleArn"] + assert event.config_rule_name == event["configRuleName"] assert event.config_rule_id == event["configRuleId"] assert event.accountid == event["accountId"] assert event.version == event["version"] assert event.invoking_event.message_type == invoking_event["messageType"] + assert event.invoking_event.notification_creation_time == invoking_event["notificationCreationTime"] + assert event.invoking_event.record_version == invoking_event["recordVersion"] assert event.invoking_event.raw_configuration_item_summary == invoking_event["configurationItemSummary"] assert ( event.invoking_event.configuration_item_summary.change_type @@ -2110,6 +2158,7 @@ def test_aws_config_rule_scheduled(): assert event.event_left_scope == event["eventLeftScope"] assert event.execution_role_arn == event["executionRoleArn"] assert event.config_rule_arn == event["configRuleArn"] + assert event.config_rule_name == event["configRuleName"] assert event.config_rule_id == event["configRuleId"] assert event.accountid == event["accountId"] assert event.version == event["version"] From 0db1025b1deca00d1bc9b49b11da856426f1f875 Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Mon, 1 May 2023 19:02:18 +0100 Subject: [PATCH 10/14] docs: highlight --- docs/utilities/data_classes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/utilities/data_classes.md b/docs/utilities/data_classes.md index 127fe15f315..0d8fe92eeb9 100644 --- a/docs/utilities/data_classes.md +++ b/docs/utilities/data_classes.md @@ -465,7 +465,7 @@ In this example, we also use the new Logger `correlation_id` and built-in `corre ### AWS Config Rule === "aws_config_rule.py" - ```python hl_lines="1 7" + ```python hl_lines="3 11" --8<-- "examples/event_sources/src/aws_config_rule.py" ``` From 70f8380610ac52f831c7625a8709640ab6ad6b2e Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Wed, 14 Jun 2023 18:28:59 +0100 Subject: [PATCH 11/14] commenting --- .../utilities/data_classes/aws_config_rule_event.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws_lambda_powertools/utilities/data_classes/aws_config_rule_event.py b/aws_lambda_powertools/utilities/data_classes/aws_config_rule_event.py index 71e52d98b5b..70a965b918e 100644 --- a/aws_lambda_powertools/utilities/data_classes/aws_config_rule_event.py +++ b/aws_lambda_powertools/utilities/data_classes/aws_config_rule_event.py @@ -17,7 +17,7 @@ def get_invoke_event( if message_type == "OversizedConfigurationItemChangeNotification": return AWSConfigOversizedConfiguration(invoking_event) - # Default return is ConfigurationChanged + # Default return is AWSConfigConfigurationChanged return AWSConfigConfigurationChanged(invoking_event) From 06b3319c7eeafd32c7ffdd3f5133c9340a683992 Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Wed, 14 Jun 2023 18:37:05 +0100 Subject: [PATCH 12/14] Commit --- .../utilities/data_classes/aws_config_rule_event.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws_lambda_powertools/utilities/data_classes/aws_config_rule_event.py b/aws_lambda_powertools/utilities/data_classes/aws_config_rule_event.py index 70a965b918e..2b9e7991576 100644 --- a/aws_lambda_powertools/utilities/data_classes/aws_config_rule_event.py +++ b/aws_lambda_powertools/utilities/data_classes/aws_config_rule_event.py @@ -17,7 +17,7 @@ def get_invoke_event( if message_type == "OversizedConfigurationItemChangeNotification": return AWSConfigOversizedConfiguration(invoking_event) - # Default return is AWSConfigConfigurationChanged + # Default return is AWSConfigConfigurationChanged event return AWSConfigConfigurationChanged(invoking_event) From 39ae25cb05a56c78748c4442d1687d45beb0d695 Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Wed, 14 Jun 2023 22:49:45 +0100 Subject: [PATCH 13/14] feat: adding cache to json fields --- .../data_classes/aws_config_rule_event.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/aws_lambda_powertools/utilities/data_classes/aws_config_rule_event.py b/aws_lambda_powertools/utilities/data_classes/aws_config_rule_event.py index 2b9e7991576..0832cda7e8a 100644 --- a/aws_lambda_powertools/utilities/data_classes/aws_config_rule_event.py +++ b/aws_lambda_powertools/utilities/data_classes/aws_config_rule_event.py @@ -1,7 +1,7 @@ from __future__ import annotations import json -from typing import Dict, List, Optional +from typing import Any, Dict, List, Optional from aws_lambda_powertools.utilities.data_classes.common import DictWrapper @@ -273,6 +273,11 @@ class AWSConfigRuleEvent(DictWrapper): - https://docs.aws.amazon.com/config/latest/developerguide/evaluate-config_develop-rules_lambda-functions.html """ + def __init__(self, data: Dict[str, Any]): + super().__init__(data) + self._invoking_event: Optional[Any] = None + self._rule_parameters: Optional[Any] = None + @property def version(self) -> str: """The version of the event.""" @@ -283,7 +288,10 @@ def invoking_event( self, ) -> AWSConfigConfigurationChanged | AWSConfigScheduledNotification | AWSConfigOversizedConfiguration: """The invoking payload of the event.""" - return get_invoke_event(json.loads(self["invokingEvent"])) + if self._invoking_event is None: + self._invoking_event = self["invokingEvent"] + + return get_invoke_event(json.loads(self._invoking_event)) @property def raw_invoking_event(self) -> str: @@ -293,7 +301,10 @@ def raw_invoking_event(self) -> str: @property def rule_parameters(self) -> Dict: """The parameters of the event.""" - return json.loads(self["ruleParameters"]) + if self._rule_parameters is None: + self._rule_parameters = self["ruleParameters"] + + return json.loads(self._rule_parameters) @property def result_token(self) -> str: From b0ebf6575ff3c1c323c903559f664e54093622de Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Thu, 15 Jun 2023 13:40:35 +0100 Subject: [PATCH 14/14] doc: adding docstring --- .../data_classes/aws_config_rule_event.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/aws_lambda_powertools/utilities/data_classes/aws_config_rule_event.py b/aws_lambda_powertools/utilities/data_classes/aws_config_rule_event.py index 0832cda7e8a..2bfa2df61c5 100644 --- a/aws_lambda_powertools/utilities/data_classes/aws_config_rule_event.py +++ b/aws_lambda_powertools/utilities/data_classes/aws_config_rule_event.py @@ -9,6 +9,20 @@ def get_invoke_event( invoking_event: dict, ) -> AWSConfigConfigurationChanged | AWSConfigScheduledNotification | AWSConfigOversizedConfiguration: + """ + Returns the corresponding event object based on the messageType in the invoking event. + + Parameters + ---------- + invoking_event: dict + The invoking event received. + + Returns + ------- + AWSConfigConfigurationChanged | AWSConfigScheduledNotification | AWSConfigOversizedConfiguration: + The event object based on the messageType in the invoking event. + """ + message_type = invoking_event.get("messageType") if message_type == "ScheduledNotification":