Skip to content

Commit c0a098b

Browse files
Adding documentation
1 parent aa0e0d3 commit c0a098b

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

docs/core/event_handler/api_gateway.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,22 @@ OpenAPI 3 lets you describe APIs protected using the following security schemes:
11151115
--8<-- "examples/event_handler_rest/src/swagger_with_oauth2.py"
11161116
```
11171117

1118+
#### OpenAPI extensions
1119+
1120+
For a better experience when working with Lambda and Amazon API Gateway, customers can define extensions using the `openapi_extensions` parameter. We support defining OpenAPI extensions at the following levels of the OpenAPI JSON Schema: Root, Servers, Operation, and Security Schemes.
1121+
1122+
???+ warning
1123+
We do not support the `x-amazon-apigateway-any-method` and `x-amazon-apigateway-integrations` extensions.
1124+
1125+
```python hl_lines="9 15 25 28" title="Adding OpenAPI extensions"
1126+
--8<-- "examples/event_handler_rest/src/working_with_openapi_extensions.py"
1127+
```
1128+
1129+
1. Server level
1130+
2. Operation level
1131+
3. Security scheme level
1132+
4. Root level
1133+
11181134
### Custom serializer
11191135

11201136
You can instruct event handler to use a custom serializer to best suit your needs, for example take into account Enums when serializing.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from aws_lambda_powertools.event_handler import APIGatewayRestResolver
2+
from aws_lambda_powertools.event_handler.openapi.models import APIKey, APIKeyIn, Server
3+
4+
app = APIGatewayRestResolver(enable_validation=True)
5+
6+
servers = Server(
7+
url="http://example.com",
8+
description="Example server",
9+
openapi_extensions={"x-amazon-apigateway-endpoint-configuration": {"vpcEndpoint": "myendpointid"}}, # (1)!
10+
)
11+
12+
13+
@app.get(
14+
"/hello",
15+
openapi_extensions={"x-amazon-apigateway-integration": {"type": "aws", "uri": "my_lambda_arn"}}, # (2)!
16+
)
17+
def hello():
18+
return app.get_openapi_json_schema(
19+
servers=[servers],
20+
security_schemes={
21+
"apikey": APIKey(
22+
name="X-API-KEY",
23+
description="API KeY",
24+
in_=APIKeyIn.header,
25+
openapi_extensions={"x-amazon-apigateway-authorizer": "custom"}, # (3)!
26+
),
27+
},
28+
openapi_extensions={"x-amazon-apigateway-gateway-responses": {"DEFAULT_4XX"}}, # (4)!
29+
)
30+
31+
32+
def lambda_handler(event, context):
33+
return app.resolve(event, context)

0 commit comments

Comments
 (0)