Aws lambda 如何在CloudFormation模板中定义无服务器Api函数的模型

Aws lambda 如何在CloudFormation模板中定义无服务器Api函数的模型,aws-lambda,amazon-cloudformation,aws-api-gateway,aws-serverless,Aws Lambda,Amazon Cloudformation,Aws Api Gateway,Aws Serverless,有关我的模板的相关部分,请参见下文。我不知道如何为Api设置模型。如果我将模型部分从MyApi中删除,“sam deploy”会说:“相关API不会定义任何模型”。那么,如何为Api和as函数请求模型添加模型呢 次要问题: 可以在外部json/yaml文件中定义模型吗 如何定义响应的模型 我可以在单独的模板文件中介绍模型吗 谢谢 Resources: MyApi: Type: AWS::Serverless::Api Properties: StageName:

有关我的模板的相关部分,请参见下文。我不知道如何为Api设置模型。如果我将模型部分从MyApi中删除,“sam deploy”会说:“相关API不会定义任何模型”。那么,如何为Api和as函数请求模型添加模型呢

次要问题:

可以在外部json/yaml文件中定义模型吗

如何定义响应的模型

我可以在单独的模板文件中介绍模型吗

谢谢

Resources:
  MyApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: test
      Models:
        ???

  PostNewItem:
    Type: AWS::ApiGateway::Model
    Properties:
      RestApiId: !Ref MyApi
      Name: PostNewItem
      ContentType: application/json
      Schema:
        $schema: 'http://json-schema.org/draft-04/schema#'
        title: NewItemModel
        type: object
        properties:
          name:
            type: string
          description:
            type: string
          ....

  MyFunction:
    Type: AWS::Serverless::Function
    Properties:
      ...
      Events:
        AddItem:
          Type: Api
          Properties:
            Path: /item
            Method: post
            RestApiId:
              !Ref MyApi
            RequestModel:
              Model: !Ref PostNewItem
              Required: true

为了回答我自己的问题,在无服务器的情况下,不需要AWS::ApiGateway::Models,而是使用Api定义它们

 MyApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: test
      Models:
        PostPointModel:
          type: object
          required:
            - name
          properties:
            name:
              type: string
            description:
              type: string

你提到这篇文章了吗?它告诉您如何在模板中定义模型是的,我有。它没有告诉我们如何用AWS::Serverless::api定义它们我们如何在api事件中使用它(模型)?