.Net Core 6 + AWS Lambda 无法处理请求正文中的 base64 数据

.Net Core 6 + AWS Lambda unable to handle base64 data in request body

提问人:M. Ko 提问时间:11/17/2023 最后编辑:M. Ko 更新时间:11/17/2023 访问量:36

问:

我使用 VS 2022 发布到 lambda 工具将 .net core 最小 API 发布到 lambda。API 接受需要上传到 S3 的图像的 base64 字符串。问题是当我从 Postman 调用请求时,lambda 失败并出现 (504) 网关超时错误。如果参数为空,则终结点工作正常。这是我在文件中的 lambda 托管。photoProgram.cs

builder.Services.AddAWSLambdaHosting(LambdaEventSource.RestApi);

来自 Postman 的请求正文

{
    "photo": "/9j/4AAQSkZ.....",
    "ext": "png"
}

文件内容server.template

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Transform": "AWS::Serverless-2016-10-31",
  "Description": "An AWS Serverless Application that uses the ASP.NET Core framework running in Amazon Lambda.",
  "Parameters": {},
  "Conditions": {},
  "Resources": {
    "AspNetCoreFunction": {
      "Type": "AWS::Serverless::Function",
      "Properties": {
        "Handler": "xxx",
        "Runtime": "dotnet6",
        "CodeUri": "",
        "MemorySize": 256,
        "Timeout": 30,
        "Role": null,
        "Policies": [
          "AWSLambda_FullAccess",
          "AWSLambdaVPCAccessExecutionRole"
        ],
        "Events": {
          "ProxyResource": {
            "Type": "Api",
            "Properties": {
              "Path": "/{proxy+}",
              "Method": "ANY"
            }
          },
          "RootResource": {
            "Type": "Api",
            "Properties": {
              "Path": "/",
              "Method": "ANY"
            }
          }
        }
      }
    }
  },
  "Outputs": {
    "ApiURL": {
      "Description": "API endpoint URL for Prod environment",
      "Value": {
        "Fn::Sub": "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/"
      }
    }
  }
}

的内容。aws-lambda-tools-defaults.json

{
    "Information" : [
        "...."
    ],
    "profile"     : "default",
    "region"      : "ap-southeast-1",
    "configuration" : "Release",
    "s3-prefix"     : "xxx/",
    "template"      : "serverless.template",
    "template-parameters" : "",
    "s3-bucket"           : "xxx",
    "stack-name"          : "xxx"
}
C# REST .Net-Core AWS-Lambda 开发操作

评论

1赞 Denis Micheal 11/17/2023
不应将代码(或错误/异常、日志、配置、项目文件或以文本形式表示的任何其他内容)作为图像发布
0赞 Ankush Jain 11/21/2023
你还在寻找答案吗?

答: 暂无答案