-
Notifications
You must be signed in to change notification settings - Fork 432
feat(jmespath): new built-in envelopes to unwrap S3 events #2169
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
heitorlessa
merged 6 commits into
aws-powertools:develop
from
leandrodamascena:jmespath/envelopes
May 1, 2023
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ef81b2f
feat(jmespath): adding new envelopes + docs + small fix
leandrodamascena 0de8370
feat(jmespath): text
leandrodamascena b13a6f9
Merge branch 'develop' into jmespath/envelopes
leandrodamascena 7528d07
chore: addressing Ruben's feedback
leandrodamascena a5152dc
feat(jmespath): addressing Heitor's feedback
leandrodamascena ef54196
chore: break message in two sentences.
heitorlessa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,16 +64,24 @@ We provide built-in envelopes for popular AWS Lambda event sources to easily dec | |
|
||
These are all built-in envelopes you can use along with their expression as a reference: | ||
|
||
| Envelope | JMESPath expression | | ||
| --------------------------------- | ------------------------------------------------------------- | | ||
| **`API_GATEWAY_REST`** | `powertools_json(body)` | | ||
| **`API_GATEWAY_HTTP`** | `API_GATEWAY_REST` | | ||
| **`SQS`** | `Records[*].powertools_json(body)` | | ||
| **`SNS`** | `Records[0].Sns.Message | powertools_json(@)` | | ||
| **`EVENTBRIDGE`** | `detail` | | ||
| **`CLOUDWATCH_EVENTS_SCHEDULED`** | `EVENTBRIDGE` | | ||
| **`KINESIS_DATA_STREAM`** | `Records[*].kinesis.powertools_json(powertools_base64(data))` | | ||
| **`CLOUDWATCH_LOGS`** | `awslogs.powertools_base64_gzip(data) | powertools_json(@).logEvents[*]` | | ||
| Envelope | JMESPath expression | | ||
| --------------------------------- | ------------------------------------------------------------------------------------------ | | ||
| **`API_GATEWAY_HTTP`** | `powertools_json(body)` | | ||
| **`API_GATEWAY_REST`** | `powertools_json(body)` | | ||
| **`CLOUDWATCH_EVENTS_SCHEDULED`** | `detail` | | ||
| **`CLOUDWATCH_LOGS`** | `awslogs.powertools_base64_gzip(data) | powertools_json(@).logEvents[*]` | | ||
| **`EVENTBRIDGE`** | `detail` | | ||
| **`KINESIS_DATA_STREAM`** | `Records[*].kinesis.powertools_json(powertools_base64(data))` | | ||
| **`S3_EVENTBRIDGE_SQS`** | `Records[*].powertools_json(body).detail` | | ||
| **`S3_RAWSNS_KINESIS_FIREHOSE`** | `records[*].powertools_json(powertools_base64(data)).Records[0]` | | ||
| **`S3_RAWSNS_SQS`** | `Records[*].powertools_json(body).Records[0]` | | ||
| **`S3_SNS_KINESIS_FIREHOSE`** | `records[*].powertools_json(powertools_base64(data)).powertools_json(Message).Records[0]` | | ||
| **`S3_SNS_SQS`** | `Records[*].powertools_json(body).powertools_json(Message).Records[0]` | | ||
| **`SNS`** | `Records[0].Sns.Message | powertools_json(@)` | | ||
| **`SQS`** | `Records[*].powertools_json(body)` | | ||
|
||
???+ tip | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Niiiice!! You can make it slightly better by:
Write, review, cut the unnecessary words without losing its original intent, and ship it <3 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
If you're using architectures that involve sending event notifications from S3 to SNS and then to SQS or Kinesis Data Firehose, consider enabling [raw message delivery](https://docs.aws.amazon.com/sns/latest/dg/sns-large-payload-raw-message-delivery.html){target="_blank"} option in Amazon SNS. This can help reduce the payload by stripping the SNS metadata. | ||
leandrodamascena marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Advanced | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 7 additions & 3 deletions
10
examples/jmespath_functions/src/extract_data_from_builtin_envelope.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
from aws_lambda_powertools import Logger | ||
from aws_lambda_powertools.utilities.jmespath_utils import ( | ||
envelopes, | ||
extract_data_from_envelope, | ||
) | ||
from aws_lambda_powertools.utilities.typing import LambdaContext | ||
|
||
logger = Logger() | ||
|
||
|
||
def handler(event: dict, context: LambdaContext) -> dict: | ||
payload = extract_data_from_envelope(data=event, envelope=envelopes.SQS) | ||
customer_id = payload.get("customerId") # now deserialized | ||
records = extract_data_from_envelope(data=event, envelope=envelopes.SQS) | ||
for record in records: # records is a list | ||
leandrodamascena marked this conversation as resolved.
Show resolved
Hide resolved
|
||
logger.info(record.get("customerId")) # now deserialized | ||
|
||
return {"customer_id": customer_id, "message": "success", "statusCode": 200} | ||
return {"message": "success", "statusCode": 200} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.