-
Notifications
You must be signed in to change notification settings - Fork 432
docs(jmespath_util): snippets split, improved, and lint #1419
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 29 commits into
aws-powertools:develop
from
leandrodamascena:chore/docs-jmespath
Aug 9, 2022
Merged
Changes from 3 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
0a1d014
docs(jmespath_function): snippets split, improved, fixed and lint
leandrodamascena 5a3a461
docs(jmespath_function): code highlights
leandrodamascena f9cd042
docs(jmespath_function): code highlights
leandrodamascena df9156b
docs(jmespath_util): include example for nested data
heitorlessa 76d7fe0
docs(jmespath_util): fix return type
heitorlessa 9f96bd8
docs(jmespath_function): Refactoring codes for demonstration purposes…
leandrodamascena 196f3c9
docs(jmespath_function): Refactoring codes for demonstration purposes…
leandrodamascena 848e660
docs(jmespath_function): Refactoring codes for demonstration purposes…
leandrodamascena 986f550
docs(jmespath_function): Refactoring codes for demonstration purposes…
leandrodamascena 0578971
docs(jmespath_function): Refactoring codes for demonstration purposes…
leandrodamascena b9889dc
docs(jmespath_function): Refactoring codes for demonstration purposes…
leandrodamascena b649842
docs(jmespath_function): Refactoring codes for demonstration purposes…
leandrodamascena 0b2505d
docs(jmespath_function): Refactoring codes - base64 envelope
leandrodamascena c4db987
docs(jmespath_function): Refactoring examples - base64-gzip envelope
leandrodamascena 8f05eb8
docs(jmespath_function): Refactoring examples - small fixes
leandrodamascena f733104
docs(jmespath_function): Refactoring examples - small fixes
leandrodamascena 4aab491
docs(jmespath_function): Refactoring examples - custom function envelope
leandrodamascena c8cba95
docs(jmespath): fix highlighting
heitorlessa b49c3f4
docs(jmespath): simplify order factory
heitorlessa 1a6a344
docs(jmespath): simplify wording
heitorlessa da920a8
docs(jmespath): correct json encoder wording
heitorlessa 9b6ae91
docs(jmespath): safer return
heitorlessa d77cd80
docs(jmespath): exception order
heitorlessa 87d8b17
docs(jmespath): adjust highlighting after refactor
heitorlessa 9c4eb04
docs(jmespath): add exception and dummy endpoint to use fn arguments
heitorlessa 05f4a4b
docs(jmespath): sync base64 with powertools_json refactor
heitorlessa aec1e71
docs(jmespath): simplify base64 gzip example
heitorlessa d673e58
docs(jmespath): emphasize important parts in jmespath example
heitorlessa e38f2a0
docs(jmespath): address old typos and wording
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
20 changes: 20 additions & 0 deletions
20
examples/jmespath_functions/src/extract_data_from_builtin_envelope.json
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"Records": [ | ||
{ | ||
"messageId": "19dd0b57-b21e-4ac1-bd88-01bbb068cb78", | ||
"receiptHandle": "MessageReceiptHandle", | ||
"body": "{\"customerId\":\"dd4649e6-2484-4993-acb8-0f9123103394\",\"booking\":{\"id\":\"5b2c4803-330b-42b7-811a-c68689425de1\",\"reference\":\"ySz7oA\",\"outboundFlightId\":\"20c0d2f2-56a3-4068-bf20-ff7703db552d\"},\"payment\":{\"receipt\":\"https:\/\/pay.stripe.com\/receipts\/acct_1Dvn7pF4aIiftV70\/ch_3JTC14F4aIiftV700iFq2CHB\/rcpt_K7QsrFln9FgFnzUuBIiNdkkRYGxUL0X\",\"amount\":100}}", | ||
"attributes": { | ||
"ApproximateReceiveCount": "1", | ||
"SentTimestamp": "1523232000000", | ||
"SenderId": "123456789012", | ||
"ApproximateFirstReceiveTimestamp": "1523232000001" | ||
}, | ||
"messageAttributes": {}, | ||
"md5OfBody": "7b270e59b47ff90a553787216d55d91d", | ||
"eventSource": "aws:sqs", | ||
"eventSourceARN": "arn:aws:sqs:us-east-1:123456789012:MyQueue", | ||
"awsRegion": "us-east-1" | ||
} | ||
] | ||
} |
9 changes: 9 additions & 0 deletions
9
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from aws_lambda_powertools.utilities.jmespath_utils import envelopes, extract_data_from_envelope | ||
from aws_lambda_powertools.utilities.typing import LambdaContext | ||
|
||
|
||
def handler(event: dict, context: LambdaContext) -> str: | ||
payload = extract_data_from_envelope(data=event, envelope=envelopes.SQS) | ||
leandrodamascena marked this conversation as resolved.
Show resolved
Hide resolved
|
||
customer_id = payload.get("customerId") # now deserialized | ||
... | ||
return {"customer_id": customer_id, "message": "success", "statusCode": 200} |
3 changes: 3 additions & 0 deletions
3
examples/jmespath_functions/src/extract_data_from_envelope.json
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"body": "{\"customerId\":\"dd4649e6-2484-4993-acb8-0f9123103394\"}" | ||
} |
9 changes: 9 additions & 0 deletions
9
examples/jmespath_functions/src/extract_data_from_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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from aws_lambda_powertools.utilities.jmespath_utils import extract_data_from_envelope | ||
from aws_lambda_powertools.utilities.typing import LambdaContext | ||
|
||
|
||
def handler(event: dict, context: LambdaContext): | ||
payload = extract_data_from_envelope(data=event, envelope="powertools_json(body)") | ||
customer_id = payload.get("customerId") # now deserialized | ||
... | ||
return {"customer_id": customer_id, "message": "success", "statusCode": 200} |
9 changes: 9 additions & 0 deletions
9
examples/jmespath_functions/src/powertools_base64_gzip_jmespath_function.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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import powertools_base64_gzip_jmespath_schema as schemas | ||
|
||
from aws_lambda_powertools.utilities.validation import validate | ||
|
||
sample_event = { | ||
"data": "H4sIACZAXl8C/52PzUrEMBhFX2UILpX8tPbHXWHqIOiq3Q1F0ubrWEiakqTWofTdTYYB0YWL2d5zvnuTFellBIOedoiyKH5M0iwnlKH7HZL6dDB6ngLDfLFYctUKjie9gHFaS/sAX1xNEq525QxwFXRGGMEkx4Th491rUZdV3YiIZ6Ljfd+lfSyAtZloacQgAkqSJCGhxM6t7cwwuUGPz4N0YKyvO6I9WDeMPMSo8Z4Ca/kJ6vMEYW5f1MX7W1lVxaG8vqX8hNFdjlc0iCBBSF4ERT/3Pl7RbMGMXF2KZMh/C+gDpNS7RRsp0OaRGzx0/t8e0jgmcczyLCWEePhni/23JWalzjdu0a3ZvgEaNLXeugEAAA==" # noqa: E501 | ||
} | ||
|
||
validate(event=sample_event, schema=schemas.INPUT, envelope="powertools_base64_gzip(data) | powertools_json(@)") | ||
heitorlessa marked this conversation as resolved.
Show resolved
Hide resolved
|
39 changes: 39 additions & 0 deletions
39
examples/jmespath_functions/src/powertools_base64_gzip_jmespath_schema.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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
INPUT = { | ||
"$schema": "http://json-schema.org/draft-07/schema", | ||
"$id": "http://example.com/example.json", | ||
"type": "object", | ||
"title": "Sample schema", | ||
"description": "The root schema comprises the entire JSON document.", | ||
"examples": [{"message": "hello world", "username": "lessa"}], | ||
"required": ["message", "username"], | ||
"properties": { | ||
"message": { | ||
"$id": "#/properties/message", | ||
"type": "string", | ||
"title": "The message", | ||
"examples": ["hello world"], | ||
"maxLength": 100, | ||
}, | ||
"username": { | ||
"$id": "#/properties/username", | ||
"type": "string", | ||
"title": "The username", | ||
"examples": ["lessa"], | ||
"maxLength": 30, | ||
}, | ||
}, | ||
} | ||
|
||
OUTPUT = { | ||
"$schema": "http://json-schema.org/draft-07/schema", | ||
"$id": "http://example.com/example.json", | ||
"type": "object", | ||
"title": "Sample outgoing schema", | ||
"description": "The root schema comprises the entire JSON document.", | ||
"examples": [{"statusCode": 200, "body": "response"}], | ||
"required": ["statusCode", "body"], | ||
"properties": { | ||
"statusCode": {"$id": "#/properties/statusCode", "type": "integer", "title": "The statusCode"}, | ||
"body": {"$id": "#/properties/body", "type": "string", "title": "The response"}, | ||
}, | ||
} |
7 changes: 7 additions & 0 deletions
7
examples/jmespath_functions/src/powertools_base64_jmespath_function.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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import powertools_base64_jmespath_schema as schemas | ||
|
||
from aws_lambda_powertools.utilities.validation import validate | ||
|
||
sample_event = {"data": "eyJtZXNzYWdlIjogImhlbGxvIGhlbGxvIiwgInVzZXJuYW1lIjogImJsYWggYmxhaCJ9="} | ||
|
||
validate(event=sample_event, schema=schemas.INPUT, envelope="powertools_json(powertools_base64(data))") | ||
heitorlessa marked this conversation as resolved.
Show resolved
Hide resolved
|
Oops, something went wrong.
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.