Skip to content
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

feat(data-classes): add KafkaEvent and KafkaEventRecord #1485

Merged
merged 13 commits into from
Sep 5, 2022

Conversation

lyoung-confluent
Copy link
Contributor

@lyoung-confluent lyoung-confluent commented Aug 30, 2022

Issue number: #1484

Summary

This change adds a data class for Kafka event sources either from self-managed Apache Kafka or Amazon MSK.

Changes

A new data class KafkaEvent is introduced which includes a records property/generator. The returned KafkaEventRecord class has a variety of useful properties for decoding the record key, value and headers.

User experience

from aws_lambda_powertools.utilities.data_classes import event_source, KafkaEvent

@event_source(data_class=KafkaEvent)
def handler(event: KafkaEvent, context: LambdaContext):
	for record in event.records:
		print(record.decoded_key, record.json_value)

Checklist

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

Is this a breaking change?

Not 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.


View rendered docs/utilities/data_classes.md

@lyoung-confluent lyoung-confluent requested a review from a team as a code owner August 30, 2022 17:17
@lyoung-confluent lyoung-confluent requested review from am29d and removed request for a team August 30, 2022 17:17
@boring-cyborg boring-cyborg bot added documentation Improvements or additions to documentation tests labels Aug 30, 2022
@boring-cyborg
Copy link

boring-cyborg bot commented Aug 30, 2022

Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need.

@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 30, 2022
@github-actions github-actions bot added the feature New feature or functionality label Aug 31, 2022
@rubenfonseca rubenfonseca requested review from leandrodamascena and removed request for am29d August 31, 2022 11:29
@leandrodamascena
Copy link
Contributor

Hi @lyoung-confluent! Indeed this is an awesome PR! Thanks a lot for taking the time to help improve the project! 🥇

I'm going to start doing a review on this PR today and let you know if we need to make some small changes.

Copy link
Contributor

@leandrodamascena leandrodamascena left a comment

Choose a reason for hiding this comment

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

Hello @lyoung-confluent! I suggested some changes in this PR.

tests/functional/test_data_classes.py Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

Codecov Report

Merging #1485 (bd9c8a6) into develop (2cf38cc) will decrease coverage by 0.40%.
The diff coverage is 92.85%.

@@             Coverage Diff             @@
##           develop    #1485      +/-   ##
===========================================
- Coverage    99.89%   99.48%   -0.41%     
===========================================
  Files          124      126       +2     
  Lines         5588     5672      +84     
  Branches       634      661      +27     
===========================================
+ Hits          5582     5643      +61     
- Misses           2       14      +12     
- Partials         4       15      +11     
Impacted Files Coverage Δ
...a_powertools/utilities/data_classes/kafka_event.py 92.75% <92.75%> (ø)
...mbda_powertools/utilities/data_classes/__init__.py 100.00% <100.00%> (ø)
...bda_powertools/utilities/data_classes/alb_event.py 90.47% <0.00%> (-9.53%) ⬇️
aws_lambda_powertools/__init__.py 100.00% <0.00%> (ø)
aws_lambda_powertools/utilities/batch/__init__.py 100.00% <0.00%> (ø)
aws_lambda_powertools/event_handler/api_gateway.py 100.00% <0.00%> (ø)
...ws_lambda_powertools/utilities/batch/exceptions.py 100.00% <0.00%> (ø)
...lambda_powertools/utilities/data_classes/common.py 100.00% <0.00%> (ø)
.../utilities/data_classes/api_gateway_proxy_event.py 100.00% <0.00%> (ø)
aws_lambda_powertools/utilities/batch/sqs.py
... and 2 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@leandrodamascena
Copy link
Contributor

Hey @lyoung-confluent. I split the tests into 2 to make it clearer what is being tested and added 1 more field to test the bootstrapserver as a raw string. I think it's good for me to merge. Do you have any more considerations?

🚀 ✈️

@lyoung-confluent
Copy link
Contributor Author

Looks good to me, thanks for the quick feedback/review @leandrodamascena!

@heitorlessa heitorlessa changed the title feat(data-classes): Add KafkaEvent and KafkaEventRecord feat(data-classes): add KafkaEvent and KafkaEventRecord Sep 5, 2022
@leandrodamascena leandrodamascena merged commit d3a0007 into aws-powertools:develop Sep 5, 2022
@boring-cyborg
Copy link

boring-cyborg bot commented Sep 5, 2022

Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience!

heitorlessa added a commit that referenced this pull request Sep 9, 2022
* develop:
  chore(deps-dev): bump aws-cdk-lib from 2.40.0 to 2.41.0 (#1507)
  update changelog with latest changes
  feat(tracer): support methods with the same name (ABCs) by including fully qualified name in v2 (#1486)
  chore(deps-dev): bump aws-cdk-aws-apigatewayv2-integrations-alpha from 2.39.1a0 to 2.40.0a0 (#1496)
  chore(deps-dev): bump mkdocs-material from 8.4.2 to 8.4.3 (#1504)
  chore(deps): bump pydantic from 1.10.1 to 1.10.2 (#1502)
  update changelog with latest changes
  feat(data-classes): add KafkaEvent and KafkaEventRecord (#1485)
  chore(deps-dev): bump pytest from 7.1.2 to 7.1.3 (#1497)
  update changelog with latest changes
  feat(event_handler): add cookies as 1st class citizen in v2 (#1487)
  chore(deps-dev): bump black from 22.6.0 to 22.8.0 (#1494)
  chore(deps-dev): bump aws-cdk-lib from 2.39.1 to 2.40.0 (#1495)
  chore(maintenance): add discord link to first PR and first issue (#1493)
  update changelog with latest changes
  refactor(batch): remove legacy sqs_batch_processor (#1492)
  chore(deps): bump pydantic from 1.10.0 to 1.10.1 (#1491)
  chore(deps-dev): bump flake8-variables-names from 0.0.4 to 0.0.5 (#1490)
rubenfonseca pushed a commit that referenced this pull request Sep 13, 2022
Co-authored-by: Leandro Damascena <leandro.damascena@gmail.com>
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 feature New feature or functionality size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants