【问题标题】:serverless: custom response parameter mappings in HttpApi无服务器:HttpApi 中的自定义响应参数映射
【发布时间】:2022-10-18 04:04:19
【问题描述】:

我正在尝试从我的 API 发送自定义响应标头,我尝试使用 events.response.statusCodes 但它不起作用,看起来它仅针对http 而不是针对httpApi 事件实现。

functions:
  myfunction:
    name: test
    handler: src/index.handler
    events:
      - httpApi:
          path: /graphql
          method: post
          response:
            statusCodes:
              200:
                headers:
                  Strict-Transport-Security: "'max-age=31536000'"
              500:
                headers:
                  Strict-Transport-Security: "'max-age=31536000'"

【问题讨论】:

    标签: amazon-web-services api aws-api-gateway serverless serverless-framework


    【解决方案1】:

    你是正确的,它还没有为httpApi 实现。但它在 AWS 级别上受 HTTP API 支持,因此您可以使用以下语法手动覆盖创建的 AWS::ApiGatewayV2::Integration 的属性:

    resources:
      extensions:
        <LogicalIdOfYourIntegrationResource>: 
          Properties:
            ResponseParameters: ...
    

    请参阅 CloudFormation 文档以获取该资源以供参考:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-integration.html#cfn-apigatewayv2-integration-responseparameters

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-29
      • 2017-05-24
      • 1970-01-01
      • 2020-04-03
      • 1970-01-01
      • 1970-01-01
      • 2021-12-12
      • 2021-12-24
      相关资源
      最近更新 更多