Skip to content

Commit cc59bde

Browse files
author
Michael Brewer
committed
Merge branch 'develop' into feat-roadmap-35
2 parents 08b91d3 + cd15ee9 commit cc59bde

File tree

6 files changed

+175
-101
lines changed

6 files changed

+175
-101
lines changed

CHANGELOG.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,56 @@ This project follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) fo
77

88
## [Unreleased]
99

10+
11+
## 1.23.0 - 2021-12-20
12+
13+
### Bug Fixes
14+
15+
* **apigateway:** allow list of HTTP methods in route method ([#838](https://github.com/awslabs/aws-lambda-powertools-python/issues/838))
16+
* **event-sources:** pass authorizer data to APIGatewayEventAuthorizer ([#897](https://github.com/awslabs/aws-lambda-powertools-python/issues/897))
17+
* **event-sources:** handle claimsOverrideDetails set to null ([#878](https://github.com/awslabs/aws-lambda-powertools-python/issues/878))
18+
* **idempotency:** include decorated fn name in hash ([#869](https://github.com/awslabs/aws-lambda-powertools-python/issues/869))
19+
* **metrics:** explicit type to single_metric ctx manager ([#865](https://github.com/awslabs/aws-lambda-powertools-python/issues/865))
20+
* **parameters:** mypy appconfig transform and return types ([#877](https://github.com/awslabs/aws-lambda-powertools-python/issues/877))
21+
* **parser:** mypy overload parse when using envelope ([#885](https://github.com/awslabs/aws-lambda-powertools-python/issues/885))
22+
* **parser:** kinesis sequence number is str, not int ([#907](https://github.com/awslabs/aws-lambda-powertools-python/issues/907))
23+
* **parser:** mypy support for payload type override as models ([#883](https://github.com/awslabs/aws-lambda-powertools-python/issues/883))
24+
* **tracer:** add warm start annotation (ColdStart=False) ([#851](https://github.com/awslabs/aws-lambda-powertools-python/issues/851))
25+
26+
### Documentation
27+
28+
* **nav**: reference cloudformation custom resource helper (CRD) ([#914](https://github.com/awslabs/aws-lambda-powertools-python/issues/914))
29+
* add new public Slack invite
30+
* disable search blur in non-prod env
31+
* update Lambda Layers version
32+
* **apigateway:** add new not_found feature ([#915](https://github.com/awslabs/aws-lambda-powertools-python/issues/915))
33+
* **apigateway:** fix sample layout provided ([#864](https://github.com/awslabs/aws-lambda-powertools-python/issues/864))
34+
* **appsync:** fix users.py typo to locations [#830](https://github.com/awslabs/aws-lambda-powertools-python/issues/830)
35+
* **lambda_layer:** fix CDK layer syntax
36+
37+
### Features
38+
39+
* **apigateway:** add exception_handler support ([#898](https://github.com/awslabs/aws-lambda-powertools-python/issues/898))
40+
* **apigateway:** access parent api resolver from router ([#842](https://github.com/awslabs/aws-lambda-powertools-python/issues/842))
41+
* **batch:** new BatchProcessor for SQS, DynamoDB, Kinesis ([#886](https://github.com/awslabs/aws-lambda-powertools-python/issues/886))
42+
* **logger:** allow handler with custom kwargs signature ([#913](https://github.com/awslabs/aws-lambda-powertools-python/issues/913))
43+
* **tracer:** add service annotation when service is set ([#861](https://github.com/awslabs/aws-lambda-powertools-python/issues/861))
44+
45+
### Maintenance
46+
47+
* minor housekeeping before release ([#912](https://github.com/awslabs/aws-lambda-powertools-python/issues/912))
48+
* correct pr label order
49+
* **ci:** split latest docs workflow
50+
* **deps:** bump fastjsonschema from 2.15.1 to 2.15.2 ([#891](https://github.com/awslabs/aws-lambda-powertools-python/issues/891))
51+
* **deps:** bump actions/setup-python from 2.2.2 to 2.3.0 ([#831](https://github.com/awslabs/aws-lambda-powertools-python/issues/831))
52+
* **deps:** support arm64 when developing locally ([#862](https://github.com/awslabs/aws-lambda-powertools-python/issues/862))
53+
* **deps:** bump actions/setup-python from 2.3.0 to 2.3.1 ([#852](https://github.com/awslabs/aws-lambda-powertools-python/issues/852))
54+
* **deps:** bump aws-xray-sdk from 2.8.0 to 2.9.0 ([#876](https://github.com/awslabs/aws-lambda-powertools-python/issues/876))
55+
* **deps-dev:** bump mypy from 0.910 to 0.920 ([#903](https://github.com/awslabs/aws-lambda-powertools-python/issues/903))
56+
* **deps-dev:** bump flake8 from 3.9.2 to 4.0.1 ([#789](https://github.com/awslabs/aws-lambda-powertools-python/issues/789))
57+
* **deps-dev:** bump black from 21.10b0 to 21.11b1 ([#839](https://github.com/awslabs/aws-lambda-powertools-python/issues/839))
58+
* **deps-dev:** bump black from 21.11b1 to 21.12b0 ([#872](https://github.com/awslabs/aws-lambda-powertools-python/issues/872))
59+
1060
## 1.22.0 - 2021-11-17
1161

1262
Tenet update! We've updated **Idiomatic** tenet to **Progressive** to reflect the new Router feature in Event Handler, and more importantly the new wave of customers coming from SRE, Data Analysis, and Data Science background.

docs/core/event_handler/api_gateway.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,93 @@ Similarly to [Query strings](#query-strings-and-payload), you can access headers
478478
return app.resolve(event, context)
479479
```
480480

481+
482+
### Handling not found routes
483+
484+
By default, we return `404` for any unmatched route.
485+
486+
You can use **`not_found`** decorator to override this behaviour, and return a custom **`Response`**.
487+
488+
=== "app.py"
489+
490+
```python hl_lines="11 13 16" title="Handling not found"
491+
from aws_lambda_powertools import Logger, Tracer
492+
from aws_lambda_powertools.logging import correlation_paths
493+
from aws_lambda_powertools.event_handler import content_types
494+
from aws_lambda_powertools.event_handler.api_gateway import ApiGatewayResolver, Response
495+
from aws_lambda_powertools.event_handler.exceptions import NotFoundError
496+
497+
tracer = Tracer()
498+
logger = Logger()
499+
app = ApiGatewayResolver()
500+
501+
@app.not_found
502+
@tracer.capture_method
503+
def handle_not_found_errors(exc: NotFoundError) -> Response:
504+
# Return 418 upon 404 errors
505+
logger.info(f"Not found route: {app.current_event.path}")
506+
return Response(
507+
status_code=418,
508+
content_type=content_types.TEXT_PLAIN,
509+
body="I'm a teapot!"
510+
)
511+
512+
513+
@app.get("/catch/me/if/you/can")
514+
@tracer.capture_method
515+
def catch_me_if_you_can():
516+
return {"message": "oh hey"}
517+
518+
@logger.inject_lambda_context(correlation_id_path=correlation_paths.API_GATEWAY_REST)
519+
@tracer.capture_lambda_handler
520+
def lambda_handler(event, context):
521+
return app.resolve(event, context)
522+
```
523+
524+
525+
### Exception handling
526+
527+
You can use **`exception_handler`** decorator with any Python exception. This allows you to handle a common exception outside your route, for example validation errors.
528+
529+
=== "app.py"
530+
531+
```python hl_lines="10 15" title="Exception handling"
532+
from aws_lambda_powertools import Logger, Tracer
533+
from aws_lambda_powertools.logging import correlation_paths
534+
from aws_lambda_powertools.event_handler import content_types
535+
from aws_lambda_powertools.event_handler.api_gateway import ApiGatewayResolver, Response
536+
537+
tracer = Tracer()
538+
logger = Logger()
539+
app = ApiGatewayResolver()
540+
541+
@app.exception_handler(ValueError)
542+
def handle_value_error(ex: ValueError):
543+
metadata = {"path": app.current_event.path}
544+
logger.error(f"Malformed request: {ex}", extra=metadata)
545+
546+
return Response(
547+
status_code=400,
548+
content_type=content_types.TEXT_PLAIN,
549+
body="Invalid request",
550+
)
551+
552+
553+
@app.get("/hello")
554+
@tracer.capture_method
555+
def hello_name():
556+
name = app.current_event.get_query_string_value(name="name")
557+
if name is not None:
558+
raise ValueError("name query string must be present")
559+
return {"message": f"hello {name}"}
560+
561+
@logger.inject_lambda_context(correlation_id_path=correlation_paths.API_GATEWAY_REST)
562+
@tracer.capture_lambda_handler
563+
def lambda_handler(event, context):
564+
return app.resolve(event, context)
565+
```
566+
567+
481568
### Raising HTTP errors
482569

483570
You can easily raise any HTTP Error back to the client using `ServiceError` exception.

docs/index.md

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ This project separates core utilities that will be available in other runtimes v
2323

2424
Powertools is available in the following formats:
2525

26-
* **Lambda Layer**: [**arn:aws:lambda:{region}:017000801446:layer:AWSLambdaPowertoolsPython:4**](#){: .copyMe} :clipboard:
26+
* **Lambda Layer**: [**arn:aws:lambda:{region}:017000801446:layer:AWSLambdaPowertoolsPython:6 :clipboard:**](#){: .copyMe}
2727
* **PyPi**: **`pip install aws-lambda-powertools`**
2828

2929
### Lambda Layer
@@ -36,23 +36,23 @@ You can include Lambda Powertools Lambda Layer using [AWS Lambda Console](https:
3636

3737
| Region | Layer ARN
3838
|--------------------------- | ---------------------------
39-
| `us-east-1` | [arn:aws:lambda:us-east-1:017000801446:layer:AWSLambdaPowertoolsPython:4](#){: .copyMe} :clipboard:
40-
| `us-east-2` | [arn:aws:lambda:us-east-2:017000801446:layer:AWSLambdaPowertoolsPython:4](#){: .copyMe} :clipboard:
41-
| `us-west-1` | [arn:aws:lambda:us-west-1:017000801446:layer:AWSLambdaPowertoolsPython:4](#){: .copyMe} :clipboard:
42-
| `us-west-2` | [arn:aws:lambda:us-west-2:017000801446:layer:AWSLambdaPowertoolsPython:4](#){: .copyMe} :clipboard:
43-
| `ap-south-1` | [arn:aws:lambda:ap-south-1:017000801446:layer:AWSLambdaPowertoolsPython:4](#){: .copyMe} :clipboard:
44-
| `ap-northeast-1` | [arn:aws:lambda:ap-northeast-1:017000801446:layer:AWSLambdaPowertoolsPython:4](#){: .copyMe} :clipboard:
45-
| `ap-northeast-2` | [arn:aws:lambda:ap-northeast-2:017000801446:layer:AWSLambdaPowertoolsPython:4](#){: .copyMe} :clipboard:
46-
| `ap-northeast-3` | [arn:aws:lambda:ap-northeast-3:017000801446:layer:AWSLambdaPowertoolsPython:4](#){: .copyMe} :clipboard:
47-
| `ap-southeast-1` | [arn:aws:lambda:ap-southeast-1:017000801446:layer:AWSLambdaPowertoolsPython:4](#){: .copyMe} :clipboard:
48-
| `ap-southeast-2` | [arn:aws:lambda:ap-southeast-2:017000801446:layer:AWSLambdaPowertoolsPython:4](#){: .copyMe} :clipboard:
49-
| `eu-central-1` | [arn:aws:lambda:eu-central-1:017000801446:layer:AWSLambdaPowertoolsPython:4](#){: .copyMe} :clipboard:
50-
| `eu-west-1` | [arn:aws:lambda:eu-west-1:017000801446:layer:AWSLambdaPowertoolsPython:4](#){: .copyMe} :clipboard:
51-
| `eu-west-2` | [arn:aws:lambda:eu-west-2:017000801446:layer:AWSLambdaPowertoolsPython:4](#){: .copyMe} :clipboard:
52-
| `eu-west-3` | [arn:aws:lambda:eu-west-3:017000801446:layer:AWSLambdaPowertoolsPython:4](#){: .copyMe} :clipboard:
53-
| `eu-north-1` | [arn:aws:lambda:eu-north-1:017000801446:layer:AWSLambdaPowertoolsPython:4](#){: .copyMe} :clipboard:
54-
| `ca-central-1` | [arn:aws:lambda:ca-central-1:017000801446:layer:AWSLambdaPowertoolsPython:4](#){: .copyMe} :clipboard:
55-
| `sa-east-1` | [arn:aws:lambda:sa-east-1:017000801446:layer:AWSLambdaPowertoolsPython:4](#){: .copyMe} :clipboard:
39+
| `us-east-1` | [arn:aws:lambda:us-east-1:017000801446:layer:AWSLambdaPowertoolsPython:6 :clipboard:](#){: .copyMe}
40+
| `us-east-2` | [arn:aws:lambda:us-east-2:017000801446:layer:AWSLambdaPowertoolsPython:6 :clipboard:](#){: .copyMe}
41+
| `us-west-1` | [arn:aws:lambda:us-west-1:017000801446:layer:AWSLambdaPowertoolsPython:6 :clipboard:](#){: .copyMe}
42+
| `us-west-2` | [arn:aws:lambda:us-west-2:017000801446:layer:AWSLambdaPowertoolsPython:6 :clipboard:](#){: .copyMe}
43+
| `ap-south-1` | [arn:aws:lambda:ap-south-1:017000801446:layer:AWSLambdaPowertoolsPython:6 :clipboard:](#){: .copyMe}
44+
| `ap-northeast-1` | [arn:aws:lambda:ap-northeast-1:017000801446:layer:AWSLambdaPowertoolsPython:6 :clipboard:](#){: .copyMe}
45+
| `ap-northeast-2` | [arn:aws:lambda:ap-northeast-2:017000801446:layer:AWSLambdaPowertoolsPython:6 :clipboard:](#){: .copyMe}
46+
| `ap-northeast-3` | [arn:aws:lambda:ap-northeast-3:017000801446:layer:AWSLambdaPowertoolsPython:6 :clipboard:](#){: .copyMe}
47+
| `ap-southeast-1` | [arn:aws:lambda:ap-southeast-1:017000801446:layer:AWSLambdaPowertoolsPython:6 :clipboard:](#){: .copyMe}
48+
| `ap-southeast-2` | [arn:aws:lambda:ap-southeast-2:017000801446:layer:AWSLambdaPowertoolsPython:6 :clipboard:](#){: .copyMe}
49+
| `eu-central-1` | [arn:aws:lambda:eu-central-1:017000801446:layer:AWSLambdaPowertoolsPython:6 :clipboard:](#){: .copyMe}
50+
| `eu-west-1` | [arn:aws:lambda:eu-west-1:017000801446:layer:AWSLambdaPowertoolsPython:6 :clipboard:](#){: .copyMe}
51+
| `eu-west-2` | [arn:aws:lambda:eu-west-2:017000801446:layer:AWSLambdaPowertoolsPython:6 :clipboard:](#){: .copyMe}
52+
| `eu-west-3` | [arn:aws:lambda:eu-west-3:017000801446:layer:AWSLambdaPowertoolsPython:6 :clipboard:](#){: .copyMe}
53+
| `eu-north-1` | [arn:aws:lambda:eu-north-1:017000801446:layer:AWSLambdaPowertoolsPython:6 :clipboard:](#){: .copyMe}
54+
| `ca-central-1` | [arn:aws:lambda:ca-central-1:017000801446:layer:AWSLambdaPowertoolsPython:6 :clipboard:](#){: .copyMe}
55+
| `sa-east-1` | [arn:aws:lambda:sa-east-1:017000801446:layer:AWSLambdaPowertoolsPython:6 :clipboard:](#){: .copyMe}
5656

5757
=== "SAM"
5858

@@ -61,7 +61,7 @@ You can include Lambda Powertools Lambda Layer using [AWS Lambda Console](https:
6161
Type: AWS::Serverless::Function
6262
Properties:
6363
Layers:
64-
- !Sub arn:aws:lambda:${AWS::Region}:017000801446:layer:AWSLambdaPowertoolsPython:4
64+
- !Sub arn:aws:lambda:${AWS::Region}:017000801446:layer:AWSLambdaPowertoolsPython:6
6565
```
6666

6767
=== "Serverless framework"
@@ -71,7 +71,7 @@ You can include Lambda Powertools Lambda Layer using [AWS Lambda Console](https:
7171
hello:
7272
handler: lambda_function.lambda_handler
7373
layers:
74-
- arn:aws:lambda:${aws:region}:017000801446:layer:AWSLambdaPowertoolsPython:4
74+
- arn:aws:lambda:${aws:region}:017000801446:layer:AWSLambdaPowertoolsPython:6
7575
```
7676

7777
=== "CDK"
@@ -87,7 +87,7 @@ You can include Lambda Powertools Lambda Layer using [AWS Lambda Console](https:
8787
powertools_layer = aws_lambda.LayerVersion.from_layer_version_arn(
8888
self,
8989
id="lambda-powertools",
90-
layer_version_arn=f"arn:aws:lambda:{env.region}:017000801446:layer:AWSLambdaPowertoolsPython:4"
90+
layer_version_arn=f"arn:aws:lambda:{env.region}:017000801446:layer:AWSLambdaPowertoolsPython:6"
9191
)
9292
aws_lambda.Function(self,
9393
'sample-app-lambda',
@@ -136,7 +136,7 @@ You can include Lambda Powertools Lambda Layer using [AWS Lambda Console](https:
136136
role = aws_iam_role.iam_for_lambda.arn
137137
handler = "index.test"
138138
runtime = "python3.9"
139-
layers = ["arn:aws:lambda:{region}:017000801446:layer:AWSLambdaPowertoolsPython:4"]
139+
layers = ["arn:aws:lambda:{region}:017000801446:layer:AWSLambdaPowertoolsPython:6"]
140140

141141
source_code_hash = filebase64sha256("lambda_function_payload.zip")
142142
}
@@ -155,7 +155,7 @@ You can include Lambda Powertools Lambda Layer using [AWS Lambda Console](https:
155155
? Do you want to configure advanced settings? Yes
156156
...
157157
? Do you want to enable Lambda layers for this function? Yes
158-
? Enter up to 5 existing Lambda layer ARNs (comma-separated): arn:aws:lambda:eu-central-1:017000801446:layer:AWSLambdaPowertoolsPython:4
158+
? Enter up to 5 existing Lambda layer ARNs (comma-separated): arn:aws:lambda:eu-central-1:017000801446:layer:AWSLambdaPowertoolsPython:6
159159
❯ amplify push -y
160160

161161

@@ -166,14 +166,18 @@ You can include Lambda Powertools Lambda Layer using [AWS Lambda Console](https:
166166
- Name: <NAME-OF-FUNCTION>
167167
? Which setting do you want to update? Lambda layers configuration
168168
? Do you want to enable Lambda layers for this function? Yes
169-
? Enter up to 5 existing Lambda layer ARNs (comma-separated): arn:aws:lambda:eu-central-1:017000801446:layer:AWSLambdaPowertoolsPython:4
169+
? Enter up to 5 existing Lambda layer ARNs (comma-separated): arn:aws:lambda:eu-central-1:017000801446:layer:AWSLambdaPowertoolsPython:6
170170
? Do you want to edit the local lambda function now? No
171171
```
172172

173173
=== "Get the Layer .zip contents"
174174
Change {region} to your AWS region, e.g. `eu-west-1`
175175

176-
**`aws lambda get-layer-version-by-arn --arn arn:aws:lambda:{region}:017000801446:layer:AWSLambdaPowertoolsPython:4 --region {region}`**
176+
```bash title="AWS CLI"
177+
aws lambda get-layer-version-by-arn --arn arn:aws:lambda:{region}:017000801446:layer:AWSLambdaPowertoolsPython:6 --region {region}
178+
```
179+
180+
The pre-signed URL to download this Lambda Layer will be within `Location` key.
177181

178182
!!! warning "Limitations"
179183

@@ -208,7 +212,7 @@ If using SAM, you can include this SAR App as part of your shared Layers stack,
208212
Properties:
209213
Location:
210214
ApplicationId: arn:aws:serverlessrepo:eu-west-1:057560766410:applications/aws-lambda-powertools-python-layer
211-
SemanticVersion: 1.22.0 # change to latest semantic version available in SAR
215+
SemanticVersion: 1.23.0 # change to latest semantic version available in SAR
212216

213217
MyLambdaFunction:
214218
Type: AWS::Serverless::Function
@@ -236,7 +240,7 @@ If using SAM, you can include this SAR App as part of your shared Layers stack,
236240
Location:
237241
ApplicationId: arn:aws:serverlessrepo:eu-west-1:057560766410:applications/aws-lambda-powertools-python-layer
238242
# Find latest from github.com/awslabs/aws-lambda-powertools-python/releases
239-
SemanticVersion: 1.22.0
243+
SemanticVersion: 1.23.0
240244
```
241245

242246
=== "CDK"
@@ -246,7 +250,7 @@ If using SAM, you can include this SAR App as part of your shared Layers stack,
246250

247251
POWERTOOLS_BASE_NAME = 'AWSLambdaPowertools'
248252
# Find latest from github.com/awslabs/aws-lambda-powertools-python/releases
249-
POWERTOOLS_VER = '1.22.0'
253+
POWERTOOLS_VER = '1.23.0'
250254
POWERTOOLS_ARN = 'arn:aws:serverlessrepo:eu-west-1:057560766410:applications/aws-lambda-powertools-python-layer'
251255

252256
class SampleApp(core.Construct):

0 commit comments

Comments
 (0)