Headers are received in Camel-Case
See original GitHub issueWhen running sam local start-api
, I’m getting headers in Camel-Case, (see X-Api-Key and X-User-Id), however. the deployed lambda function is receiving the headers in lower-case (x-api-key and x-user-id).
My local code is working as of 2020-03-09 17:00 GMT+8, and I’m trying to understand why the behaviour is different now.
In sam local
:
{
'headers': {
'X-Api-Key': '<redacted>',
'X-User-Id': '<redacted>',
'User-Agent': 'PostmanRuntime/7.22.0',
'Accept': '*/*',
'Cache-Control': 'no-cache',
'Host': 'localhost:3000',
'Accept-Encoding': 'gzip, deflate, br',
'Connection': 'keep-alive',
'X-Forwarded-Proto': 'http',
'X-Forwarded-Port': '3000'
},
'multiValueHeaders': {
'X-Api-Key': ['<redacted>'],
'X-User-Id': ['<redacted>'],
'User-Agent': ['PostmanRuntime/7.22.0'],
'Accept': ['*/*'],
'Cache-Control': ['no-cache'],
'Host': ['localhost:3000'],
'Accept-Encoding': ['gzip, deflate, br'],
'Connection': ['keep-alive'],
'X-Forwarded-Proto': ['http'],
'X-Forwarded-Port': ['3000']
}
}
In AWS Lambda:
{
'headers': {
'Accept': '*/*',
'Accept-Encoding': 'gzip, deflate, br',
'Cache-Control': 'no-cache',
'Host': '<redacted>',
'User-Agent': 'PostmanRuntime/7.22.0',
'X-Amzn-Trace-Id': 'Root=1-5e6739e1-d6161c849faa6e9a369f680c',
'x-api-key': '<redacted>',
'X-Forwarded-For': '175.143.101.237',
'X-Forwarded-Port': '443',
'X-Forwarded-Proto': 'https',
'x-user-id': '<redacted>'
},
'multiValueHeaders': {
'Accept': ['*/*'],
'Accept-Encoding': ['gzip, deflate, br'],
'Cache-Control': ['no-cache'],
'Host': ['<host>'],
'User-Agent': ['PostmanRuntime/7.22.0'],
'X-Amzn-Trace-Id': ['Root=1-5e6739e1-d6161c849faa6e9a369f680c'],
'x-api-key': ['<redacted>'],
'X-Forwarded-For': ['<IP address>'],
'X-Forwarded-Port': ['443'],
'X-Forwarded-Proto': ['https'],
'x-user-id': ['<redacted>']
}
}
Snippet of template.yaml
I’m using.
Resources:
BasePythonLayer:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: pythonBaseLayer
ContentUri: /app/LambdaCodes/LambdaLayers/PythonLayer
CompatibleRuntimes:
- python3.7
VendorFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: vendor-function
Handler: vendorFunction.lambda_handler
Runtime: python3.7
Timeout: 120
CodeUri: ./VendorFunction/
Layers:
- !Ref BasePythonLayer
Events:
Vendor:
Type: Api
Properties:
Path: /vendor
Method: ANY
- OS: Using docker,
python:alpine
sam --version
: SAM CLI, version 0.40.0
Issue Analytics
- State:
- Created 4 years ago
- Reactions:7
- Comments:19 (7 by maintainers)
Top Results From Across the Web
Headers are received in Camel-Case · Issue #1860 - GitHub
When running sam local start-api, I'm getting headers in Camel-Case, (see X-Api-Key and X-User-Id), however. the deployed lambda function is ...
Read more >Angular 10 / .Net 4.8 Request Headers Changed to be Camel ...
HTTP headers are case insensitive. Whenever you lookup a header value by Key it needs to be a case insensitive match. Request.
Read more >Http Response headers going back to the consumer always ...
Http Response headers going back to the consumer always being converted to all lower case and NOT camel case. MuleSoft Runtime auto-converts the...
Read more >Split CamelCase headers in M (And a fix for the Record of ...
You can split CamelCase headers using the Table.TransformColumnName and the following list generator custom function:.
Read more >Headers are getting convert into lower case? | Layer7 API ...
I am facing issue when client is sending Headers in CAPITAL letters, those headers are being converted into lower by API Gateway.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’d recommend updating the function code to use a
CaseInsensitiveDict
object just likerequests
does. The Lambda PowerTools also handle this for you with theget_header_value
method. In the HTTP protocol, headers are meant to be case insensitive. Right now it’s thex-api-key
header but in the future the issues could apply to any other header.I was wrong, API Gateway doesn’t lower everything, in some cases headers remain capitalized. Thank you @jfuss for explaining this here https://github.com/aws/aws-sam-cli/issues/3083#issuecomment-887632702
I have closed #3117 for that reason.