将Cognito验证类型设置为CloudFormation中的链接

时间:2018-01-31 08:42:24

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

我正在尝试弄清楚如何在我的CloudFormation模板中将验证类型从Code(默认)设置为Link

在网站上我可以在这里设置:example

如果我看一下docs,就没有提到。 我的CloudFormation看起来像

SomeUserPoolResourceName:
  Type: AWS::Cognito::UserPool
  Properties:
    UserPoolName: SomeResource_User_Pool
    EmailVerificationType: Link  # I want something like this
    EmailVerificationSubject: 'Your verification link'
    EmailVerificationMessage: 'Please click the link below to verify your email address. {##Verify Email##}' # fails because {####} is required
    AliasAttributes:
      - email
    AutoVerifiedAttributes:
      - email
    Policies:
      PasswordPolicy:
        - .... 
    Schema:
      - ....

是否可以通过CloudFormation进行配置?

4 个答案:

答案 0 :(得分:9)

不,目前不可能。根据更新的CreateUserPool API,新的VerificationMessageTemplate参数将允许我们执行此操作,但cloudformation尚未支持此功能。 AWS Support表示存在针对该功能的现有功能请求。您可以查看自定义云信息资源作为解决方法。

答案 1 :(得分:1)

尝试一下:

SomeUserPoolResourceName:
  Type: AWS::Cognito::UserPool
  Properties:
    UserPoolName: SomeResource_User_Pool
    VerificationMessageTemplate:
       DefaultEmailOption: CONFIRM_WITH_LINK
    EmailVerificationSubject: 'Your verification link'
    EmailVerificationMessage: 'Please click the link below to verify your email address. {##Verify Email##}' # fails because {####} is required
    AliasAttributes:
      - email
    AutoVerifiedAttributes:
      - email
    Policies:
      PasswordPolicy:
        - .... 
    Schema:

更改此部分:

EmailVerificationType: Link  # I want something like this

针对:

VerificationMessageTemplate:
  DefaultEmailOption: CONFIRM_WITH_LINK

答案 2 :(得分:1)

感谢Daniel Golgher

该解决方法被证明是一个很好的解决方案。

我的代码如下:

UserPool:
    Type: "AWS::Cognito::UserPool"
    Properties:
      UserPoolName:
        Fn::If:
          - IsDevelopment
          - !Sub "${ApplicationName}-${Environment}-${User}-${Module}-user-pool"
          - !Sub "${ApplicationName}-${Environment}-${Module}-user-pool"
      UsernameAttributes: [email]
      AutoVerifiedAttributes:
        - email
      VerificationMessageTemplate:
        DefaultEmailOption: CONFIRM_WITH_LINK
      EmailVerificationSubject: verify your email id for ${ApplicationName}
      EmailVerificationMessage: Please click the link below to verify your email address. {####}

答案 3 :(得分:0)

如果您有自定义消息lambda触发器,则可以轻松地在其中放置链接。

<a href="https://[your domain]/confirmUser?client_id=[your clientId]&user_name=" + event.request.userAttributes.sub + "&confirmation_code=" + event.request.codeParameter + ">Click here to verify your account</a>