Skip to content

Commit d1996a6

Browse files
committed
Merge branch 'develop' into chore/refactor-e2e
* develop: chore(ci): update changelog with latest changes docs(parser): minor grammar fix (aws-powertools#1427) chore(ci): update changelog with latest changes docs(apigateway): removes duplicate admonition (aws-powertools#1426) chore(ci): update changelog with latest changes docs(jmespath_util): snippets split, improved, and lint (aws-powertools#1419) chore(ci): reduce payload and only send prod notification
2 parents 0280d9f + 6380b63 commit d1996a6

23 files changed

+608
-175
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
## Bug Fixes
88

9+
* **ci:** move from pip-tools to poetry on layers to fix conflicts
910
* **ci:** typo and bust gh actions cache
1011
* **ci:** use poetry to resolve layer deps; pip for CDK
1112
* **ci:** disable poetry venv for layer workflow as cdk ignores venv
@@ -17,12 +18,20 @@
1718

1819
## Documentation
1920

21+
* **apigateway:** removes duplicate admonition ([#1426](https://github.com/awslabs/aws-lambda-powertools-python/issues/1426))
22+
* **jmespath_util:** snippets split, improved, and lint ([#1419](https://github.com/awslabs/aws-lambda-powertools-python/issues/1419))
2023
* **layer:** upgrade to 1.27.0
24+
* **layer:** upgrade to 1.27.0
25+
* **parser:** minor grammar fix ([#1427](https://github.com/awslabs/aws-lambda-powertools-python/issues/1427))
2126

2227
## Maintenance
2328

2429
* **ci:** update changelog with latest changes
2530
* **ci:** update changelog with latest changes
31+
* **ci:** reduce payload and only send prod notification
32+
* **ci:** update changelog with latest changes
33+
* **ci:** update changelog with latest changes
34+
* **ci:** update changelog with latest changes
2635

2736

2837
<a name="v1.27.0"></a>

docs/core/event_handler/api_gateway.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,6 @@ Each dynamic route you set must be part of your function signature. This allows
135135
???+ tip
136136
You can also nest dynamic paths, for example `/todos/<todo_id>/<todo_status>`.
137137

138-
???+ tip
139-
You can also nest dynamic paths, for example `/todos/<todo_id>/<todo_status>`.
140-
141138
#### Catch-all routes
142139

143140
???+ note

docs/utilities/jmespath_functions.md

Lines changed: 91 additions & 163 deletions
Large diffs are not rendered by default.

docs/utilities/parser.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ Parser is best suited for those looking for a trade-off between defining their m
524524

525525
We export most common classes, exceptions, and utilities from Pydantic as part of parser e.g. `from aws_lambda_powertools.utilities.parser import BaseModel`.
526526

527-
If what's your trying to use isn't available as part of the high level import system, use the following escape hatch mechanism:
527+
If what you're trying to use isn't available as part of the high level import system, use the following escape hatch mechanism:
528528

529529
```python title="Pydantic import escape hatch"
530530
from aws_lambda_powertools.utilities.parser.pydantic import <what you'd like to import'>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"Records": [
3+
{
4+
"messageId": "19dd0b57-b21e-4ac1-bd88-01bbb068cb78",
5+
"receiptHandle": "MessageReceiptHandle",
6+
"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}}",
7+
"attributes": {
8+
"ApproximateReceiveCount": "1",
9+
"SentTimestamp": "1523232000000",
10+
"SenderId": "123456789012",
11+
"ApproximateFirstReceiveTimestamp": "1523232000001"
12+
},
13+
"messageAttributes": {},
14+
"md5OfBody": "7b270e59b47ff90a553787216d55d91d",
15+
"eventSource": "aws:sqs",
16+
"eventSourceARN": "arn:aws:sqs:us-east-1:123456789012:MyQueue",
17+
"awsRegion": "us-east-1"
18+
}
19+
]
20+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from aws_lambda_powertools.utilities.jmespath_utils import envelopes, extract_data_from_envelope
2+
from aws_lambda_powertools.utilities.typing import LambdaContext
3+
4+
5+
def handler(event: dict, context: LambdaContext) -> dict:
6+
payload = extract_data_from_envelope(data=event, envelope=envelopes.SQS)
7+
customer_id = payload.get("customerId") # now deserialized
8+
9+
return {"customer_id": customer_id, "message": "success", "statusCode": 200}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"body": "{\"customerId\":\"dd4649e6-2484-4993-acb8-0f9123103394\"}",
3+
"deeply_nested": [
4+
{
5+
"some_data": [
6+
1,
7+
2,
8+
3
9+
]
10+
}
11+
]
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from aws_lambda_powertools.utilities.jmespath_utils import extract_data_from_envelope
2+
from aws_lambda_powertools.utilities.typing import LambdaContext
3+
4+
5+
def handler(event: dict, context: LambdaContext) -> dict:
6+
payload = extract_data_from_envelope(data=event, envelope="powertools_json(body)")
7+
customer_id = payload.get("customerId") # now deserialized
8+
9+
# also works for fetching and flattening deeply nested data
10+
some_data = extract_data_from_envelope(data=event, envelope="deeply_nested[*].some_data[]")
11+
12+
return {"customer_id": customer_id, "message": "success", "context": some_data, "statusCode": 200}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import base64
2+
import binascii
3+
import gzip
4+
import json
5+
6+
import powertools_base64_gzip_jmespath_schema as schemas
7+
from jmespath.exceptions import JMESPathTypeError
8+
9+
from aws_lambda_powertools.utilities.typing import LambdaContext
10+
from aws_lambda_powertools.utilities.validation import SchemaValidationError, validate
11+
12+
13+
def lambda_handler(event, context: LambdaContext) -> dict:
14+
try:
15+
validate(event=event, schema=schemas.INPUT, envelope="powertools_base64_gzip(payload) | powertools_json(@)")
16+
17+
# Alternatively, extract_data_from_envelope works here too
18+
encoded_payload = base64.b64decode(event["payload"])
19+
uncompressed_payload = gzip.decompress(encoded_payload).decode()
20+
log: dict = json.loads(uncompressed_payload)
21+
22+
return {
23+
"message": "Logs processed",
24+
"log_group": log.get("logGroup"),
25+
"owner": log.get("owner"),
26+
"success": True,
27+
}
28+
29+
except JMESPathTypeError:
30+
return return_error_message("The powertools_base64_gzip() envelope function must match a valid path.")
31+
except binascii.Error:
32+
return return_error_message("Payload must be a valid base64 encoded string")
33+
except json.JSONDecodeError:
34+
return return_error_message("Payload must be valid JSON (base64 encoded).")
35+
except SchemaValidationError as exception:
36+
# SchemaValidationError indicates where a data mismatch is
37+
return return_error_message(str(exception))
38+
39+
40+
def return_error_message(message: str) -> dict:
41+
return {"message": message, "success": False}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"payload": "H4sIACZAXl8C/52PzUrEMBhFX2UILpX8tPbHXWHqIOiq3Q1F0ubrWEiakqTWofTdTYYB0YWL2d5zvnuTFellBIOedoiyKH5M0iwnlKH7HZL6dDB6ngLDfLFYctUKjie9gHFaS/sAX1xNEq525QxwFXRGGMEkx4Th491rUZdV3YiIZ6Ljfd+lfSyAtZloacQgAkqSJCGhxM6t7cwwuUGPz4N0YKyvO6I9WDeMPMSo8Z4Ca/kJ6vMEYW5f1MX7W1lVxaG8vqX8hNFdjlc0iCBBSF4ERT/3Pl7RbMGMXF2KZMh/C+gDpNS7RRsp0OaRGzx0/t8e0jgmcczyLCWEePhni/23JWalzjdu0a3ZvgEaNLXeugEAAA=="
3+
}

0 commit comments

Comments
 (0)