Skip to content

feat(event_sources): add AWS Config Rule event data class #2175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

leandrodamascena
Copy link
Contributor

Issue number: #1667

Summary

Changes

In this PR we are adding the 3 types of events that can trigger a Lambda from an AWS Config rule.

These events are:

  • ConfigurationItemChangeNotification - AWS Config publishes an event when it detects a configuration change for a resource that is within the scope of a rule.
  • ScheduledNotification - AWS Config publishes an event when it evaluates your resources at a frequency that you specify (such as every 1 hour)
  • OversizedConfigurationItemChangeNotification - Some resource changes generate oversized configuration items

User experience

BEFORE

from aws_lambda_powertools.utilities.typing import LambdaContext
from aws_lambda_powertools import Logger
import json

logger = Logger()

def lambda_handler(event, context: LambdaContext):

    message_type = json.loads(event["invokingEvent"])["messageType"]

    logger.info(f"Logging {message_type} event rule", invoke_event=event["invokingEvent"])

    return {"Success": "OK"}

AFTER

from aws_lambda_powertools.utilities.data_classes import AWSConfigRuleEvent, event_source
from aws_lambda_powertools.utilities.typing import LambdaContext
from aws_lambda_powertools import Logger

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"}

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Apr 27, 2023
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 27, 2023
@github-actions github-actions bot added feature New feature or functionality labels Apr 27, 2023
@boring-cyborg boring-cyborg bot added the tests label Apr 28, 2023
@codecov-commenter
Copy link

codecov-commenter commented Apr 28, 2023

Codecov Report

Patch coverage: 99.50% and project coverage change: +0.06 🎉

Comparison is base (62a123c) 97.15% compared to head (8aabf85) 97.22%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2175      +/-   ##
===========================================
+ Coverage    97.15%   97.22%   +0.06%     
===========================================
  Files          156      157       +1     
  Lines         7103     7306     +203     
  Branches       519      523       +4     
===========================================
+ Hits          6901     7103     +202     
  Misses         158      158              
- Partials        44       45       +1     
Impacted Files Coverage Δ
...ls/utilities/data_classes/aws_config_rule_event.py 99.50% <99.50%> (ø)
...mbda_powertools/utilities/data_classes/__init__.py 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@pull-request-size pull-request-size bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 28, 2023
@leandrodamascena leandrodamascena marked this pull request as ready for review April 28, 2023 01:03
@leandrodamascena leandrodamascena requested a review from a team as a code owner April 28, 2023 01:03
@leandrodamascena leandrodamascena requested review from rubenfonseca and removed request for a team April 28, 2023 01:03
@leandrodamascena leandrodamascena linked an issue Apr 28, 2023 that may be closed by this pull request
2 tasks
Copy link
Contributor

@rubenfonseca rubenfonseca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a lot of great work! Just left a small change in the highlights of the docs.

@austindimmer
Copy link

This looks great, I was running in to this issue yesterday whilst building my first Custom Config rule and was about to build my own data structure to handle the incoming events. This looks to be exactly what is needed.

I look forward to this being merged.

Thanks for the efforts!

@leandrodamascena
Copy link
Contributor Author

This looks great, I was running in to this issue yesterday whilst building my first Custom Config rule and was about to build my own data structure to handle the incoming events. This looks to be exactly what is needed.

I look forward to this being merged.

Thanks for the efforts!

Hi @austindimmer! It's amazing to hear that. We are reaching out to the AWS Config team just to confirm some information about these schemas, but we will definitely do our best to get this merged as soon as possible.

Thanks.

@leandrodamascena
Copy link
Contributor Author

Hey, everyone! We haven't received any updates from the AWS Config team regarding event/schema validation and are moving forward with this PR.
To ensure this new EventSource class works as expected, we've tested extensively with many events and payloads, and in all cases, we've had success using this.

Until we get feedback from our customers that this feature is working as expected, we will not be adding Parser support.

@rubenfonseca, can you review this, please?

Copy link
Contributor

@rubenfonseca rubenfonseca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks amazing, thank you for the great work @leandrodamascena !

@rubenfonseca rubenfonseca added the event_sources Event Source Data Class utility label Jun 15, 2023
@rubenfonseca rubenfonseca merged commit ec207b1 into aws-powertools:develop Jun 15, 2023
rafaelgsr pushed a commit to rafaelgsr/aws-lambda-powertools-python that referenced this pull request Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation event_sources Event Source Data Class utility feature New feature or functionality size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: AWS Config Rule event data class
4 participants