简体   繁体   English

如何在使用来自 AWS Lambda 的 307 重定向(POST 方法和正文)在 python 中传递请求正文

[英]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.

相关问题 如何用请求正文替换golang http.NewRequest POST中的变量结构 - How to replace variable struct in golang http.NewRequest POST with request body 如何使用 AWS CDK 中的 InvokeLambda 将 JSON 传递给 AWS StepFunction 中的 lambda - How do I pass JSON to lambda in AWS StepFunction using InvokeLambda in AWS CDK 如何将参数传递给 AWS Lambda 函数 - How to pass parameters to AWS Lambda function 如何使用 GET 请求将参数传递给 AWS Lambda 函数? - How do I pass arguments to AWS Lambda functions using GET requests? 如何使用 API 网关集成访问 Node js AWS Lambda 中的 POST 参数? - How do I access a POST parameter in Node js AWS Lambda with API Gateway integration? HTTP 主体的示例 URL 编码 HTTP 来自 Z9017AFDB6E0254E5B2E8D256 的请求 - Example of HTTP body for URL Encoded HTTP Request from Twilio Studio 从 AWS Lambda 将数据发布到 Google Sheet web 应用程序 - POST data to Google Sheet web app from AWS Lambda 如何使用 Lambda 访问 AWS API Gateway 请求的 HTTP 标头? - How to access HTTP headers for request to AWS API Gateway using Lambda? AWS api 网关在响应正文中返回令牌 - AWS api gateway returning token in the response body 如何在部署 Python Bottle 服务器时通过 AWS App Runner 的健康检查测试? - How to pass health check tests on AWS App Runner while deploying Python Bottle server?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM