跳至內容

Amazon S3 对象 Lambda 传递请求的上下文中没有User-Agent标头

0

我们按照官方教程搭建了一个使用 S3 对象 Lambda 转换数据的流程,但在Lambda函数中接收传递过来的请求上下文userRequest. headers中始终没有User-Agent;其他的请求头信息都正常,该怎么处理才能获取到User-Agent? https://docs.aws.amazon.com/zh_cn/AmazonS3/latest/userguide/olap-event-context.html

请求日志

已提問 1 年前檢視次數 445 次

1 個回答
0

Based on the information provided, it appears you're experiencing an issue where the User-Agent header is not being included in the event context passed to your S3 Object Lambda function.

When S3 Object Lambda passes request context to Lambda functions, it includes various fields including headers from the original call. However, authorization-related headers are explicitly excluded from this context. It's possible that the User-Agent header is being treated as an authorization-related header or is being filtered out for security reasons.

The event context documentation confirms that certain headers may be excluded, specifically mentioning "excluding any authorization-related headers." While User-Agent isn't typically considered an authorization header, AWS might be filtering it out as part of their security practices.

To address this issue, you have a few options:

  1. Consider if you truly need the User-Agent information for your use case. If possible, design your solution to work without relying on this specific header.

  2. If the User-Agent is critical for your application, you might need to pass this information through alternative means, such as including it as part of your object metadata or as a custom parameter in your request.

  3. Check if there are any configuration options for your S3 Object Lambda Access Point that might allow you to include additional headers in the context.

The headers that are passed through to the Lambda function are limited to non-authorization headers, and it appears that User-Agent may be among those that are filtered out by default.
Sources
Event context format and usage - Amazon Simple Storage Service

已回答 1 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。