简体   繁体   English

如何在 CloudFormation 模板中将 AWS::ApiGateway::Resource 添加到 AWS::Serverless::Api

[英]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.

相关问题 在CloudFormation模板中为“ AWS :: ApiGateway :: Resource”指定ParentId - Specify ParentId for “AWS::ApiGateway::Resource” in CloudFormation template 带有Cloudformation SAM的AWS :: Serverless :: Api资源策略 - AWS::Serverless::Api Resource Policy with Cloudformation SAM 重用 AWS::ApiGateway::ApiKey 的 cloudformation 模板 - Reusing cloudformation template for AWS::ApiGateway::ApiKey 如何在AWS SAM模板中为AWS :: Serverless :: Api添加请求验证器? - How to add a request validator in a AWS SAM template for AWS::Serverless::Api? AWS无服务器和API资源 - AWS serverless and API resource Cloudformation AWS :: ApiGateway :: ClientCertificate已过期 - Cloudformation AWS::ApiGateway::ClientCertificate expired AWS APIGateway CloudFormation 指定方法所需的 Api Key? - AWS APIGateway CloudFormation specify Api Key required for method? 无法有条件地添加 AWS::Serverless::Api 资源的 Auth 属性 - Cannot add Auth property of AWS::Serverless::Api resource conditionally 在AWS Cloudformation模板中使用条件时如何管理资源依赖性? - How to manage resource dependency while using Conditions in AWS cloudformation template? 如何从AWS CloudFormation模板为特定资源类型创建堆栈 - How to create stack for specific resource types from aws cloudformation template
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM