资源之间的循环依赖:CognitoUserPool和环境

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了资源之间的循环依赖:CognitoUserPool和环境相关的知识,希望对你有一定的参考价值。

当我尝试使用Ref时,我得到一个错误:当lambda绑定到来自AWS::Cognito::UserPool的事件时,在lambda环境中使用cognitoUserPool

这是错误 The CloudFormation template is invalid: Circular dependency between resources:

无服务器代码

functions:
  cognito:
    handler: src/lambdas.cognito
    events:
      - cognitoUserPool:
          pool: General
          trigger: CustomMessage
      - cognitoUserPool:
          pool: General
          trigger: PostConfirmation
      - cognitoUserPool:
          pool: General
          trigger: PreSignUp
    environment:
      COGNITO_USER_POOL_ID:
        Ref: CognitoUserPoolGeneral

resources:
  Resources:
    CognitoIdentityPoolGeneral:
      Type: AWS::Cognito::IdentityPool
      Properties:
        IdentityPoolName: IdentityPool
        AllowUnauthenticatedIdentities: false
        CognitoIdentityProviders:
          -
            ClientId:
              Ref: CognitoUserPoolGeneralWebClient
            ProviderName:
              Fn::GetAtt: [CognitoUserPoolGeneral,ProviderName]

    CognitoIdentityPoolGeneralRoleAttachments:
      Type: AWS::Cognito::IdentityPoolRoleAttachment
      Properties:
        IdentityPoolId:
          Ref: CognitoIdentityPoolGeneral
        Roles:
          authenticated:
            Fn::GetAtt: [CognitoIdentityPoolAuthRole,Arn]
          unauthenticated:
            Fn::GetAtt: [CognitoIdentityPoolUnAuthRole,Arn]


    CognitoIdentityPoolAuthRole:
      Type: AWS::IAM::Role
      Properties:
        RoleName: CognitoIdentityAuth
        AssumeRolePolicyDocument:
          Version: '2012-10-17'
          Statement:
            -
              Effect: Allow
              Principal:
                Federated: cognito-identity.amazonaws.com
              Action: sts:AssumeRoleWithWebIdentity
              Condition:
                StringEquals:
                  cognito-identity.amazonaws.com:aud:
                    Ref: CognitoIdentityPoolGeneral
                ForAnyValue:StringLike:
                  cognito-identity.amazonaws.com:amr: authenticated



    CognitoIdentityPoolUnAuthRole:
      Type: AWS::IAM::Role
      Properties:
        RoleName: CognitoIdentityUnAuth
        AssumeRolePolicyDocument:
          Version: '2012-10-17'
          Statement:
            -
              Effect: Allow
              Principal:
                Federated: cognito-identity.amazonaws.com
              Action: sts:AssumeRoleWithWebIdentity
              Condition:
                StringEquals:
                  cognito-identity.amazonaws.com:aud:
                    Ref: CognitoIdentityPoolGeneral
                ForAnyValue:StringLike:
                  cognito-identity.amazonaws.com:amr: unauthenticated


    CognitoUserPoolGeneral:
      Type: AWS::Cognito::UserPool
      Properties:
        UserPoolName: general
        AutoVerifiedAttributes: [ email ]
        AliasAttributes: [ email ]
        Policies:
          PasswordPolicy:
            MinimumLength: 6
            RequireLowercase: false
            RequireNumbers: false
            RequireSymbols: false
            RequireUppercase: false
        Schema:
          - AttributeDataType: String
            Name: landingWebSite
            DeveloperOnlyAttribute: false
            Mutable: true
            Required: false
          - AttributeDataType: String
            Name: userAgentLocale
            DeveloperOnlyAttribute: false
            Mutable: true
            Required: false

    CognitoUserPoolGeneralWebClient:
      Type: AWS::Cognito::UserPoolClient
      Properties:
        ClientName: web
        GenerateSecret: false
        RefreshTokenValidity: 30
        UserPoolId:
          Ref: CognitoUserPoolGeneral
答案

删除以下部分:

  COGNITO_USER_POOL_ID:
    Ref: CognitoUserPoolGeneral

您的部署应该没有问题。 要获取用户池属性 - 可以在事件对象中找到用户池ID(其他属性只是查询的问题)。

以上是关于资源之间的循环依赖:CognitoUserPool和环境的主要内容,如果未能解决你的问题,请参考以下文章

如何解决资源之间的循环依赖:[s3bucketvideo, S3InvokeLambdaPermission]

sbt:模块之间的循环依赖?

Spring到底是如何解决循环依赖的?

商店之间的循环模块依赖关系

头文件之间的循环依赖

解决由于类之间的循环依赖而导致的构建错误