[英]How to add an AWS::ApiGateway::Resource to an AWS::Serverless::Api in CloudFormation template
In my CloudFormation template I create a Serverless::Api resource like so,在我的 CloudFormation 模板中,我创建了一个 Serverless::Api 资源,如下所示,
Resources:
RestApi:
Type: AWS::Serverless::Api
Properties:
StageName: v1
Auth:
DefaultAuthorizer: DefaultAuthorizer
Authorizers:
TokenAuthorizer:
FunctionArn: !GetAtt AuthorizerFunction.Arn
Then I want to add a custom resource to this API, to do that I add this resource to my template然后我想向这个 API 添加一个自定义资源,为此我将此资源添加到我的模板
Resources:
ShareResource:
Type: AWS::ApiGateway::Resource
Properties:
ParentId: !GetAtt RestApi.RootResourceId
RestApiId: !Ref RestApi
PathPart: 'share'
When I deploy the CloudFormation
template, it works and I get no errors, however, the custom ShareResource
is not in the API, it doesn't exist anywhere.当我部署
CloudFormation
模板时,它可以工作并且我没有收到任何错误,但是,自定义ShareResource
不在 API 中,它不存在于任何地方。 However, when I look at the CloudFormation
event outputs, it says the resource was created.但是,当我查看
CloudFormation
事件输出时,它说资源已创建。
How do I achieve this?我如何实现这一目标?
Just a hunch, but this potentially could be caused from not putting any methods inside the resource.只是一种预感,但这可能是由于没有在资源中放置任何方法造成的。 try adding a child AWS::ApiGateway::Method to your resource and see if cloudformation builds correctly.
尝试将子 AWS::ApiGateway::Method 添加到您的资源并查看 cloudformation 是否正确构建。 Eg
例如
Resources:
RestApi:
Type: AWS::Serverless::Api
Properties:
StageName: v1
Auth:
DefaultAuthorizer: DefaultAuthorizer
Authorizers:
TokenAuthorizer:
FunctionArn: !GetAtt AuthorizerFunction.Arn
ShareResource:
Type: AWS::ApiGateway::Resource
Properties:
ParentId: !GetAtt RestApi.RootResourceId
RestApiId: !Ref RestApi
PathPart: 'share'
MockMethod:
Type: 'AWS::ApiGateway::Method'
Properties:
RestApiId: !Ref RestApi
ResourceId: !Ref ShareResource
HttpMethod: GET
AuthorizationType: NONE
Integration:
Type: MOCK
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.