In my CloudFormation template I create a Serverless::Api resource like so,
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
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. However, when I look at the CloudFormation
event outputs, it says the resource was created.
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. 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.