如何通过Terraform配置AWS Cognito用户池的注册必填属性
问题描述
使用Terraform创建AWS Cognito用户池时,需将email、family_name和name设为注册必填属性,但当前配置执行后,注册界面未将这些字段标记为必填项,无法达到预期的注册体验要求。
解决方案
核心问题在于你定义的这三个属性的required参数都设为了false,Cognito不会将其识别为注册必填字段。只需将对应schema块中的required = false修改为required = true即可。
额外注意点:
email属于Cognito内置属性,即便已配置为alias_attributes,仍需显式设置required = true才能在注册时强制要求填写- 自定义属性
organization如果需要设为必填,也可参照同样方式修改required值
修改后的完整Terraform代码
resource "aws_cognito_user_pool" "users_pool" { name = "my-example-users" email_configuration { email_sending_account = "DEVELOPER" from_email_address = "<from-email-address>" source_arn = "<identity-arn-goes-here>" } verification_message_template { email_subject = "Your verification code" email_message = "Your verification code is {####}. " sms_message = "Your verification code is {####}. " } admin_create_user_config { invite_message_template { email_subject = "Your account details" email_message = "\nHi {username} <br/><br/>\nYour username is {username} and password is {####}. </br><br/>\nThanks<br/>\n" sms_message = "Your username is {username} and password is {####}. " } allow_admin_create_user_only = false } sms_authentication_message = "Your authentication code is {####}." password_policy { minimum_length = 8 temporary_password_validity_days = 7 require_lowercase = true require_numbers = true require_symbols = true require_uppercase = true } alias_attributes = ["email", "preferred_username"] username_configuration { case_sensitive = "true" } auto_verified_attributes = ["email"] schema { attribute_data_type = "String" name = "name" developer_only_attribute = false mutable = true required = true # 修改为true,设为必填 string_attribute_constraints { max_length = 50 min_length = 1 } } schema { attribute_data_type = "String" name = "email" developer_only_attribute = false mutable = true required = true # 修改为true,设为必填 string_attribute_constraints { max_length = 50 min_length = 1 } } schema { attribute_data_type = "String" name = "family_name" developer_only_attribute = false mutable = true required = true # 修改为true,设为必填 string_attribute_constraints { max_length = 50 min_length = 1 } } # 自定义属性,若需必填可参照上面修改required值 schema { attribute_data_type = "String" mutable = true name = "organization" string_attribute_constraints { max_length = 50 min_length = 1 } } tags = {...} }
内容的提问来源于stack exchange,提问作者Sri
相关产品推荐
相关产品推荐

