【问题标题】:AWS SAM app API multiple method declarationsAWS SAM 应用程序 API 多方法声明
【发布时间】:2022-01-30 15:00:38
【问题描述】:

我创建了 aws sam 应用程序。它有一个休息 api 客户。目前我只能添加一种 http 方法类型,GET 或 POST。

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: ""

Globals:
Function:
Timeout: 59

Resources:
  HealthFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: src/
      Handler: index.handler
      Runtime: nodejs14.x
      Architectures:
        - x86_64
      Events:
        Health:
          Type: Api 
          Properties:
            Path: /health
            Method: get
        Customers:
          Type: Api 
          Properties:
            Path: /customers
            Method: get

Outputs:
  HealthApi:
    Description: "API Gateway endpoint URL for Prod for Health function"
    Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/health"
  CustomersApi:
    Description: "API Gateway endpoint URL for Prod for Health function"
    Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/customers"

我如何声明客户 api http 方法包括 GET 和 POST?

请帮忙。

【问题讨论】:

    标签: yaml aws-sam


    【解决方案1】:

    您可以为同一路径定义多个事件。

    CustomersGetEvent:
      Type: Api
      Properties:
        Path: /customers
        Method: GET
    CustomersPostEvent:
      Type: Api
      Properties:
        Path: /customers
        Method: POST
    

    您也可以使用Method: ANY

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-27
      • 2020-07-14
      • 2019-03-13
      • 2021-10-11
      • 1970-01-01
      • 2019-09-23
      • 2018-01-24
      • 2020-05-23
      相关资源
      最近更新 更多