forked from aws-powertools/powertools-lambda-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(event_handler): add support for multiValueQueryStringParameters …
…in OpenAPI schema (aws-powertools#3667) * Initial code for multivalue querystring * Adding tests and improving code * Adding tests and improving code * Refactoging to avoid abstraction leaky * Making Pydanticv2 happy * Adding documentation * Addressing Ruben's feedback * Addressing Ruben's feedback * Mypy....
- Loading branch information
1 parent
f98ead0
commit 0519fa3
Showing
13 changed files
with
544 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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
34 changes: 34 additions & 0 deletions
34
examples/event_handler_rest/src/working_with_multi_query_values.py
This file contains 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,34 @@ | ||
from enum import Enum | ||
from typing import List | ||
|
||
from aws_lambda_powertools.event_handler import APIGatewayRestResolver | ||
from aws_lambda_powertools.event_handler.openapi.params import Query | ||
from aws_lambda_powertools.shared.types import Annotated | ||
from aws_lambda_powertools.utilities.typing import LambdaContext | ||
|
||
app = APIGatewayRestResolver(enable_validation=True) | ||
|
||
|
||
class ExampleEnum(Enum): | ||
"""Example of an Enum class.""" | ||
|
||
ONE = "value_one" | ||
TWO = "value_two" | ||
THREE = "value_three" | ||
|
||
|
||
@app.get("/todos") | ||
def get( | ||
example_multi_value_param: Annotated[ | ||
List[ExampleEnum], # (1)! | ||
Query( | ||
description="This is multi value query parameter.", | ||
), | ||
], | ||
): | ||
"""Return validated multi-value param values.""" | ||
return example_multi_value_param | ||
|
||
|
||
def lambda_handler(event: dict, context: LambdaContext) -> dict: | ||
return app.resolve(event, context) |
This file contains 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,38 @@ | ||
{ | ||
"requestContext": { | ||
"elb": { | ||
"targetGroupArn": "arn:aws:elasticloadbalancing:eu-central-1:1234567890:targetgroup/alb-c-Targe-11GDXTPQ7663S/804a67588bfdc10f" | ||
} | ||
}, | ||
"httpMethod": "GET", | ||
"path": "/todos", | ||
"multiValueQueryStringParameters": { | ||
"parameter1": ["value1","value2"], | ||
"parameter2": ["value"] | ||
}, | ||
"multiValueHeaders": { | ||
"accept": [ | ||
"*/*" | ||
], | ||
"host": [ | ||
"alb-c-LoadB-14POFKYCLBNSF-1815800096.eu-central-1.elb.amazonaws.com" | ||
], | ||
"user-agent": [ | ||
"curl/7.79.1" | ||
], | ||
"x-amzn-trace-id": [ | ||
"Root=1-62fa9327-21cdd4da4c6db451490a5fb7" | ||
], | ||
"x-forwarded-for": [ | ||
"123.123.123.123" | ||
], | ||
"x-forwarded-port": [ | ||
"80" | ||
], | ||
"x-forwarded-proto": [ | ||
"http" | ||
] | ||
}, | ||
"body": "", | ||
"isBase64Encoded": false | ||
} |
This file contains 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,51 @@ | ||
{ | ||
"version":"2.0", | ||
"routeKey":"$default", | ||
"rawPath":"/", | ||
"rawQueryString":"", | ||
"headers":{ | ||
"sec-fetch-mode":"navigate", | ||
"x-amzn-tls-version":"TLSv1.2", | ||
"sec-fetch-site":"cross-site", | ||
"accept-language":"pt-BR,pt;q=0.9", | ||
"x-forwarded-proto":"https", | ||
"x-forwarded-port":"443", | ||
"x-forwarded-for":"123.123.123.123", | ||
"sec-fetch-user":"?1", | ||
"accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", | ||
"x-amzn-tls-cipher-suite":"ECDHE-RSA-AES128-GCM-SHA256", | ||
"sec-ch-ua":"\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"102\", \"Google Chrome\";v=\"102\"", | ||
"sec-ch-ua-mobile":"?0", | ||
"x-amzn-trace-id":"Root=1-62ecd163-5f302e550dcde3b12402207d", | ||
"sec-ch-ua-platform":"\"Linux\"", | ||
"host":"<url-id>.lambda-url.us-east-1.on.aws", | ||
"upgrade-insecure-requests":"1", | ||
"cache-control":"max-age=0", | ||
"accept-encoding":"gzip, deflate, br", | ||
"sec-fetch-dest":"document", | ||
"user-agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36" | ||
}, | ||
"queryStringParameters": { | ||
"parameter1": "value1,value2", | ||
"parameter2": "value" | ||
}, | ||
"requestContext":{ | ||
"accountId":"anonymous", | ||
"apiId":"<url-id>", | ||
"domainName":"<url-id>.lambda-url.us-east-1.on.aws", | ||
"domainPrefix":"<url-id>", | ||
"http":{ | ||
"method":"GET", | ||
"path":"/", | ||
"protocol":"HTTP/1.1", | ||
"sourceIp":"123.123.123.123", | ||
"userAgent":"agent" | ||
}, | ||
"requestId":"id", | ||
"routeKey":"$default", | ||
"stage":"$default", | ||
"time":"05/Aug/2022:08:14:39 +0000", | ||
"timeEpoch":1659687279885 | ||
}, | ||
"isBase64Encoded":false | ||
} |
This file contains 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,36 @@ | ||
{ | ||
"version": "2.0", | ||
"path": "/newpath", | ||
"method": "GET", | ||
"headers": { | ||
"user_agent": "curl/7.64.1", | ||
"x-forwarded-for": "10.213.229.10", | ||
"host": "test-lambda-service-3908sdf9u3u.dkfjd93.vpc-lattice-svcs.us-east-2.on.aws", | ||
"accept": "*/*" | ||
}, | ||
"queryStringParameters": { | ||
"parameter1": [ | ||
"value1", | ||
"value2" | ||
], | ||
"parameter2": [ | ||
"value" | ||
] | ||
}, | ||
"body": "{\"message\": \"Hello from Lambda!\"}", | ||
"isBase64Encoded": false, | ||
"requestContext": { | ||
"serviceNetworkArn": "arn:aws:vpc-lattice:us-east-2:123456789012:servicenetwork/sn-0bf3f2882e9cc805a", | ||
"serviceArn": "arn:aws:vpc-lattice:us-east-2:123456789012:service/svc-0a40eebed65f8d69c", | ||
"targetGroupArn": "arn:aws:vpc-lattice:us-east-2:123456789012:targetgroup/tg-6d0ecf831eec9f09", | ||
"identity": { | ||
"sourceVpcArn": "arn:aws:ec2:region:123456789012:vpc/vpc-0b8276c84697e7339", | ||
"type" : "AWS_IAM", | ||
"principal": "arn:aws:sts::123456789012:assumed-role/example-role/057d00f8b51257ba3c853a0f248943cf", | ||
"sessionName": "057d00f8b51257ba3c853a0f248943cf", | ||
"x509SanDns": "example.com" | ||
}, | ||
"region": "us-east-2", | ||
"timeEpoch": "1696331543569073" | ||
} | ||
} |
This file contains 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
Oops, something went wrong.