Amazon cloudformation AWS SAM-SAM和x27之间的多级循环依赖关系;s lambda和api资源

Amazon cloudformation AWS SAM-SAM和x27之间的多级循环依赖关系;s lambda和api资源,amazon-cloudformation,swagger-2.0,aws-sam,Amazon Cloudformation,Swagger 2.0,Aws Sam,我正在构建一个具有“静态”资源(API、lambda LayerVersions、DynamoDB表等)和“动态”资源(lambda函数、批处理和SQS队列)的大型应用程序 为了整齐地安排这一点,我创建了多个模板文件,其中一些引用了SAM的AWS::Serverless::Application类型 在一些“模块”(1级深层嵌套堆栈)中,我有lambda作为lambda代理,它们集成的API在StaticResourcesModule嵌套堆栈中声明 但是,这些lambda需要AWS::Serve

我正在构建一个具有“静态”资源(API、lambda LayerVersions、DynamoDB表等)和“动态”资源(lambda函数、批处理和SQS队列)的大型应用程序

为了整齐地安排这一点,我创建了多个模板文件,其中一些引用了SAM的
AWS::Serverless::Application
类型

在一些“模块”(1级深层嵌套堆栈)中,我有lambda作为lambda代理,它们集成的API在
StaticResourcesModule
嵌套堆栈中声明

但是,这些lambda需要AWS::Serverless::Api的
RestApiId
属性

之所以出现循环依赖关系,是因为Swagger 2.0模板首先定义了
AWS::Serverless::Api
,以了解哪个lambda实现了什么方法(
x-amazon-apigateway-integration
uri
属性)

当lambda本身需要对API的
RestApiId
属性的引用,并且两者都在不同的堆栈中时,如何向API传递对lambda的引用?

顶级YAML模板文件如下所示:

Resources:
  StaticResourcesModule:
    Type: AWS::Serverless::Application
    Properties:
      Location: static_resources_module/template.yaml

  DataFetchingModule:
    Type: AWS::Serverless::Application
    Properties:
      Location: datafetching_module/template.yaml
      Parameters:
        MainApiId: !GetAtt StaticResourcesModule.Outputs.MainApiId
datafetching\u模块/模板.yaml

Parameters:
  MainApiId:
    Type: String
    Description: >
      Reference to the main api (AWS::Serverless::Api) resource.

Resources:
  FetchingRequestsHandler:
    Type: AWS::Serverless::Function
    Description: Handles incoming requests [...]
    Properties:
      [...]
      Events:
        ApiPostNewRequestEvent:
          Type: Api
          Properties:
            Method: post
            Path: /fetching/low-priority
            RestApiId: !Ref MainApiId
静态资源\u模块/模板.yaml

Parameters:
    FetchingRequestsHandlerArn:
        Type: String
Resources:
  MainApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: Prod
      DefinitionUri: api/swagger2_template.yaml

Outputs:
 MainApiId:
   Value: !Ref MainApi
   Description: The Main API's RestApiId which to provide to the Lambda that require an API Event (lambda proxy)
  /fetching/low-priority:
    post:
      # API integration, necessary.
      x-amazon-apigateway-integration:
        uri:
          Fn::Sub: "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${FetchingRequestsHandlerArn}/invocations"
api/swagger2\u模板.yaml

Parameters:
    FetchingRequestsHandlerArn:
        Type: String
Resources:
  MainApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: Prod
      DefinitionUri: api/swagger2_template.yaml

Outputs:
 MainApiId:
   Value: !Ref MainApi
   Description: The Main API's RestApiId which to provide to the Lambda that require an API Event (lambda proxy)
  /fetching/low-priority:
    post:
      # API integration, necessary.
      x-amazon-apigateway-integration:
        uri:
          Fn::Sub: "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${FetchingRequestsHandlerArn}/invocations"