【问题标题】:Can I set a property in CloudFormation only if the entity doesn't exist yet?仅当实体尚不存在时,我是否可以在 CloudFormation 中设置属性?
【发布时间】:2021-08-28 19:46:51
【问题描述】:

我通过 Amplify 有一个 CloudFormation,它定义了一个 Cognito 用户池。我想将从此模板部署的未来环境设置为具有UsernameConfiguration.CaseSensitive: False。如果我只是将该属性添加到我的 CloudFormation 模板,更新将失败并出现以下错误:

Reason: Updates are not allowed for property - UsernameConfiguration. (Service: AWSCognitoIdentityProvider; Status Code: 400; Error Code: InvalidParameterException; Request ID: null; Proxy: null)

有没有办法根据池是否已经存在来调整这个属性? 我希望创建的任何新环境都使用新配置,但仍允许部署旧环境。

这是 Amplify 用于创建用户池的 CloudFormation 模板的 sn-p。

    # BEGIN USER POOL RESOURCES
    UserPool:
        # Created upon user selection
        # Depends on SNS Role for Arn if MFA is enabled
        Type: AWS::Cognito::UserPool
        UpdateReplacePolicy: Retain
        Properties:
            UserPoolName:
                !If [
                    ShouldNotCreateEnvResources,
                    !Ref userPoolName,
                    !Join ["", [!Ref userPoolName, "-", !Ref env]],
                ]

            Schema:
                - Name: email
                  Required: true
                  Mutable: true

            LambdaConfig:
                PostAuthentication: !Ref functiontestcd9b6b5ePostAuthenticationArn

                PostConfirmation: !Ref functiontestcd9b6b5ePostConfirmationArn

                PreTokenGeneration: !Ref functiontestcd9b6b5ePreTokenGenerationArn

            AutoVerifiedAttributes: !Ref autoVerifiedAttributes

            EmailVerificationMessage: !Ref emailVerificationMessage
            EmailVerificationSubject: !Ref emailVerificationSubject

            Policies:
                PasswordPolicy:
                    MinimumLength: !Ref passwordPolicyMinLength
                    RequireLowercase: false
                    RequireNumbers: false
                    RequireSymbols: false
                    RequireUppercase: false

            UsernameAttributes: !Ref usernameAttributes

            MfaConfiguration: !Ref mfaConfiguration
            SmsVerificationMessage: !Ref smsVerificationMessage
            SmsAuthenticationMessage: !Ref smsAuthenticationMessage
            SmsConfiguration:
                SnsCallerArn: !GetAtt SNSRole.Arn
                ExternalId: testcd9b6b5e_role_external_id
            UsernameConfiguration:
                CaseSensitive: False

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation amazon-cognito aws-amplify


    【解决方案1】:

    有没有办法根据池是否已经存在来调整这个属性?

    遗憾的是它不可能,因为 CFN 没有检查池是否存在的功能。如果你需要这样的功能,你必须使用custom resource自己实现它。

    【讨论】:

    • 我现在所做的是创建了一个条件,检查我的“Env”变量以获取我知道它无法部署到的硬编码值列表。
    猜你喜欢
    • 2010-12-13
    • 1970-01-01
    • 2021-11-26
    • 2016-07-18
    • 2013-02-25
    • 1970-01-01
    • 2020-05-23
    • 1970-01-01
    • 2011-08-06
    相关资源
    最近更新 更多