我能够使用 Cloudformation / Serverless Application Model 定义和部署我的 API Gateway + Lambda 堆栈,并希望将模型添加到我的 API。
我已经在 YAML 中创建了模型,但它似乎无法引用Outputs
我文件部分中定义的 API。
我看到的错误是
未能创建变更集:Waiter ChangeSetCreateComplete 失败:Waiter 遇到终端故障状态状态:FAILED。
原因:模板格式错误:模板的Resources块中未解决的资源依赖[MyApi]
是否可以引用该Output
对象,或者在这种情况下它不被视为资源?即我是否需要明确定义AWS::Serverless::Api
而不是使用Output
?
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
PutItemFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: put_item
Handler: handlers.put_item
Runtime: python3.6
Events:
PutResource:
Type: Api
Properties:
Path: /
Method: put
ModelResource:
Type: AWS::ApiGateway::Model
Properties:
RestApiId:
Ref: MyApi
ContentType: "application/json"
Name: MyModel
Schema:
"$schema": "http://json-schema.org/draft-04/schema#"
type: object
properties:
id:
type: string
Outputs:
MyApi:
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/s/"