【问题标题】:Cloudformation circular dependency confusionCloudformation 循环依赖混淆
【发布时间】:2018-12-16 12:29:22
【问题描述】:

我完全迷失在 Cloudformation 的循环依赖问题上。我编写了这个模板,它非常适合从 CLI 运行,但是当我尝试从浏览器作为堆栈启动它时,我遇到了这个循环依赖问题。

谁能告诉我依赖来自哪里?

这是我得到的错误

Circular dependency between resources: [VehiclesLambda, HelloAPI, AuthorizerFuncPerm]

这是我的模板

AWSTemplateFormatVersion: '2010-09-09'
Description: Yes you can use SAM to create an Authorizer
Parameters:
  Environment:
    Type: String
    Default: dev
Outputs:
  ExampleAPIUrl:
    Value: !Sub "https://${HelloAPI}.execute-api.${AWS::Region}.amazonaws.com/${Environment}/"
Resources:
  HelloAPI:
    Type: AWS::Serverless::Api
    Properties:
      StageName: !Sub ${Environment}
      DefinitionBody:
        swagger: 2.0
        info:
          title:
            Ref: AWS::StackName
        securityDefinitions:
          test-authorizer:
            type: apiKey
            name: Authorization
            in: header
            x-amazon-apigateway-authtype: custom
            x-amazon-apigateway-authorizer:
              type: token
              authorizerUri:
                Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${AuthorizerFunc.Arn}/invocations
              authorizerResultTtlInSeconds: 5
        paths:
          /vehicles:
            get:
              x-amazon-apigateway-integration:
                httpMethod: POST
                type: aws_proxy
                uri:
                  !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${VehiclesLambda.Arn}/invocations
              responses: {}
              security:
                - test-authorizer: []
  VehiclesLambda:
    Type: AWS::Serverless::Function
    Properties:
      Handler: index.handler
      Runtime: nodejs4.3 
      CodeUri: 's3://companyrentalaws/vehicles.zip'
      MemorySize: 128 
      Timeout: 30
      Policies:
        - AWSLambdaBasicExecutionRole
      Events:
        MyEndpoint:
          Type: Api 
          Properties:
            Path: /vehicles
            Method: GET
            RestApiId:
              Ref: HelloAPI
  AuthorizerFunc:
      Type: AWS::Serverless::Function
      Properties:
        Handler: authorizer.authorizer
        Runtime: nodejs4.3
        CodeUri: 's3://companyrentalaws/authorizer.zip'
  AuthorizerFuncPerm:
      Type: AWS::Lambda::Permission
      DependsOn:
        - HelloAPI
        - AuthorizerFunc
      Properties:
        Action: lambda:InvokeFunction
        FunctionName:
          Ref: AuthorizerFunc
        Principal: apigateway.amazonaws.com

很抱歉发布了这么多代码,但不想遗漏任何内容。

【问题讨论】:

  • 为什么需要 DependsOn: - AuthorizerFuncPerm 的 HelloAPI?
  • 我只是尝试注释掉 DependOn 语句,似乎没有帮助。我有点想知道这是否与政策有关?
  • 我确实从转换中删除了语句“Transform: AWS::Serverless-2016-10-31”,它会运行,但它会生成一堆 ChangeSet,仍然不确定是什么原因造成的.
  • 发布另一个问题以获取相关信息并在此处添加您的答案,您是如何解决此问题的

标签: amazon-web-services amazon-cloudformation


【解决方案1】:

VehiclesLambda 有一个引用 HelloAPI 的属性 RestApiId。

            RestApiId:
              Ref: HelloAPI

HelloAPI Fn:GetAttr 的 VehiclesLambda 的 Arn

!Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${VehiclesLambda.Arn}/invocations

有你的循环依赖。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-10
    • 1970-01-01
    • 2021-06-29
    • 2020-11-30
    • 1970-01-01
    • 2015-01-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多