Closed
Description
Expected Behaviour
By standard HTTP header keys should not be case sensitive, and in many cases get always converted to lowercase automatically.
For example see Requests library, it defines a case-insensitive dictionary to hold the headers:
from requests.structures import CaseInsensitiveDict
Likewise Chalice uses the same structure for the headers in the request.
Current Behaviour
When using AWS Lambda Powertools the request headers are coming in a standard case-sensitive Python dictionary.
As the result of that retrieving the header by key is case-sensitive.
Code snippet
from aws_lambda_powertools.event_handler import APIGatewayRestResolver, Response
from dataclasses import dataclass
import json
app = APIGatewayRestResolver()
@app.route('/test', method=['GET'])
def test():
return Response(
body=json.dumps({
"Result": app.current_event.headers.get('testheader', 'Headers are case-sensitive')
}),
status_code=200
)
def lambda_handler(event: dict, context) -> dict:
response = app.resolve(event, context)
return response
def lambda_context():
@dataclass
class LambdaContext:
function_name: str = "testfunction"
memory_limit_in_mb: int = 128
invoked_function_arn: str = "arn:aws:lambda:us-east-1:123456789012:function:testfunction"
aws_request_id: str = "d195721c-d4d8-4b10-9c4c-ef4768865b92"
return LambdaContext()
test_event = {
"path": "/test",
"httpMethod": "GET",
"requestContext": {"requestId": "d195721c-d4d8-4b10-9c4c-ef4768865b92"},
"headers": {'testHeader':'Headers are case-insensitive'}
}
print(json.dumps(lambda_handler(test_event, lambda_context())))
Possible Solution
No response
Steps to Reproduce
In lambda code attempt to retrieve request header capitalized differently than it is on the incoming request.
Powertools for AWS Lambda (Python) version
latest
AWS Lambda function runtime
3.11
Packaging format used
Lambda Layers
Debugging logs
No response
Metadata
Metadata
Assignees
Type
Projects
Status
Shipped