[英]How to do pass a Request Body while doing a 307 Redirect with a( POST Method and body ) from AWS Lambda , in python
I need to redirect to an another end point from my AWS Lambda function.我需要从我的 AWS Lambda 函数重定向到另一个端点。 I have implemented below code in AWS Lambda function and trying to Redirect to an End Point implement in external system as a POST end point.我在 AWS Lambda 函数中实现了以下代码,并尝试重定向到外部系统中的端点实现作为 POST 端点。 I am not sure how to pass the Request Body.我不确定如何通过请求正文。
Python code is trying to redirect, but I am not sure how to pass a "new" Request Body as it is a POST Endpoint, I don't want the original body to get transmitted. Python 代码正在尝试重定向,但我不确定如何传递“新”请求主体,因为它是一个 POST 端点,我不希望传输原始主体。
Please see the Java error at the destination where it got redirected.请在重定向的目的地查看 Java 错误。
def lambda_handler(event, context):
# Create Dictionary
value = {
"language": "python33",
"greetings" : "Greetings... Hope you have been redirected"
}
# Dictionary to JSON Object using dumps() method
# Return JSON Object
return {
"headers": {"Location": "http://localhost:8080/urlcallback",'Content-Type':'application/json' ,},
'statusCode': 307,
'body': json.dumps(value)
}
The Redirected End Point is getting invoked, but with the below error in the JAVA Spring boot logs:
{
"timestamp": 1671820676750,
"status": 500,
"error": "Internal Server Error",
"exception": "org.springframework.http.converter.HttpMessageNotReadableException",
"message": "Required request body is missing: public java.util.Map<java.lang.String, java.lang.String> my.sample.service.controller.PingController.urlcallback(java.lang.String)",
"path": "/urlcallback"
}
I will greatly appreciate any suggestions or pointers. I could not find any when I checked on StackOverFlow
Note:笔记:
I tried first with basic redirect of 301 and 302, that works for a GET call, but now I get an error while doing a Redirect with POST end point and a request body as I have some sensitive data to transmit我首先尝试使用 301 和 302 的基本重定向,这适用于 GET 调用,但现在我在使用 POST 端点和请求正文进行重定向时遇到错误,因为我有一些敏感数据要传输
I am not sure how to pass a "new" Request Body as it is a POST Endpoint, I don't want the original body to get transmitted.我不确定如何传递“新”请求主体,因为它是一个 POST 端点,我不希望传输原始主体。
Based on HTTP 307 docs this is not possible: "307 guarantees that the method and the body will not be changed when the redirected request is made"基于HTTP 307 文档,这是不可能的:“307 保证在发出重定向请求时不会更改方法和正文”
You can try HTTP 303 and change the request type to GET to remove the body from the request.您可以尝试HTTP 303并将请求类型更改为 GET 以从请求中删除正文。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.