【发布时间】:2019-01-24 21:57:56
【问题描述】:
我能够使用 Cloudformation/无服务器应用程序模型定义和部署我的 API Gateway + Lambda 堆栈,并希望将模型添加到我的 API。
我在 YAML 中创建了模型,但它似乎无法引用我文件的 Outputs 部分中定义的 API。
我看到的错误是
创建变更集失败:Waiter ChangeSetCreateComplete 失败: 服务员遇到终端故障状态状态:FAILED。
原因: 模板格式错误:未解决的资源依赖项 [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/"
【问题讨论】:
标签: yaml aws-api-gateway amazon-cloudformation serverless-framework aws-serverless