【发布时间】:2020-06-10 02:37:42
【问题描述】:
有关我的模板的相关部分,请参见下文。我不知道如何为 Api 设置模型。如果我将模型部分从 MyApi 中排除,“sam deploy”会说:“相关 API 没有定义任何模型”。那么如何为 Api 添加模型和作为函数请求模型呢?
次要问题:
可以在外部 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
【问题讨论】:
-
你有没有参考这篇文章docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/… ?它告诉您如何在模板中定义模型
-
是的,我有。它没有说明如何使用 AWS::Serverless::Api 定义它们
标签: aws-lambda amazon-cloudformation aws-api-gateway aws-serverless