【问题标题】:Post a large file with ApiGatewayV2 and S3使用 ApiGatewayV2 和 S3 发布大文件
【发布时间】:2023-02-07 04:51:14
【问题描述】:

我有一个 6Mb 的文件要上传到 S3。

目前,我使用这个配置:

无服务器.yml:

lambdaApi:
  handler: public/index.php
  events:
    - httpApi: '*'

resources:
  Conditions:
  Resources:
    ApiMapping:
      Type: 'AWS::ApiGatewayV2::ApiMapping'
      Condition: HaveCustomDomain
      DependsOn: HttpApiIntegrationApi
      Properties:
        ApiMappingKey: "my-project"
        DomainName: my.domain.co
        ApiId: !Ref HttpApi
        Stage: "$default"

问题是因为我的lambdaApiLambda,我的POST请求不能超过6MB。

我试过使用这个解决方案(来自这里:https://theburningmonk.com/2020/04/hit-the-6mb-lambda-payload-limit-heres-what-you-can-do/):

但它不适用于AWS ApiGatewayV2。

当我使用这个自定义无服务器尝试插件 https://github.com/serverless-operations/serverless-apigateway-service-proxy 时:

  apiGatewayServiceProxies:
    - s3:
        path: /my/path
        method: post
        action: PutObject
        bucket: dev-connect-files
        cors: true
        requestParameters:
          # if requestParameters has a 'integration.request.path.object' property you should remove the key setting
          'integration.request.path.object': 'context.requestId'
          'integration.request.header.cache-control': "'public, max-age=31536000, immutable'"

我可以创建一个 POST 路由,但它与我的真实 API 是分离的。

我无法访问 /my/path 应该执行的 PHP 代码。

我知道我可以选择使用预签名 URL,但我暂时不想使用它。

问题:

  1. 是否可以使用这个插件 https://github.com/serverless-operations/serverless-apigateway-service-proxy 与AWS ApiGatewayV2

【问题讨论】:

    标签: amazon-web-services amazon-s3 aws-lambda aws-api-gateway


    【解决方案1】:

    也许这不是真正的答案,但是当您可以使用预签名 URL 上传大文件并避免超时、上传限制并降低成本时,为什么要为 APIGateway 付费,将操作放在 S3 上等

    https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-presigned-url.html

    此外,它更安全,因为预签名的 URL 可能会过期或限制使用

    【讨论】:

      猜你喜欢
      • 2020-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-25
      • 2020-11-28
      • 2020-11-10
      • 2014-10-11
      • 2018-12-02
      相关资源
      最近更新 更多