将AWS CDK EmailConfigurationProperty与UserPool关联

时间:2020-09-11 12:23:27

标签: java amazon-web-services aws-cdk

如何将EmailConfigurationProperty与UserPool相关联?我已经配置了两个对象,但是看不到连接它们的路径。

https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cognito.UserPool.html

https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cognito.CfnUserPool.EmailConfigurationProperty.html

public class CdkStackMain extends Stack {

    public CdkStackMain(final Construct scope, final String id, final StackProps props, StackMode stackMode) {
        super(scope, id, props);

        // other objects created here

        UserPool userPool = UserPool.Builder.create(this, myAppName+"-UserPoolv008")
                .userPoolName(myAppName)
                .autoVerify(autoVerifiedAttrs)
                .accountRecovery(AccountRecovery.EMAIL_AND_PHONE_WITHOUT_MFA)
                .selfSignUpEnabled(true)
                .passwordPolicy(passwordPolicy)
                .signInCaseSensitive(false)
                .standardAttributes(standardAtts)
                .signInAliases(signinAliases)
                .build();

        EmailConfigurationProperty emailConfigurationProperty = EmailConfigurationProperty.builder()
                .sourceArn("arn:aws:ses:us-east-1:000000000:identity/my-id")
                .from("Some Name <somename@company.com>")
                .replyToEmailAddress("Some Name <somename@company.com>")
                .build();
    }
}

1 个答案:

答案 0 :(得分:0)

从AWS CDK v1.62.0开始,UserPool高级对象没有EmailConfigurationProperty的设置器。解决方案是在CfnUserPool低级对象上使用setter。

UserPool userPool = UserPool.Builder.create(this, myAppName+"-UserPoolv010")
    .userPoolName(myAppName)
    .autoVerify(autoVerifiedAttrs)
    .accountRecovery(AccountRecovery.EMAIL_AND_PHONE_WITHOUT_MFA)
    .selfSignUpEnabled(true)
    .passwordPolicy(passwordPolicy)
    .signInCaseSensitive(false)
    .standardAttributes(standardAtts)
    .signInAliases(signinAliases)
    .lambdaTriggers(userPoolTriggers)
    .build();

EmailConfigurationProperty emailConfigurationProperty = EmailConfigurationProperty.builder()
    .emailSendingAccount(EmailSendingAccountType.DEVELOPER.toString())
    .sourceArn("arn:aws:ses:us-east-1:0000000:identity/customer_support@company.com")
    .from("customer_support@company.com")
    .replyToEmailAddress("customer_support@company.com")
    .build();

CfnUserPool cfnUserPool = (CfnUserPool)userPool.getNode().getDefaultChild();
cfnUserPool.setEmailConfiguration(emailConfigurationProperty);