admin_create_user
¶
admin_create_user(
user_pool_id: UserPoolIdType,
username: UsernameType,
*,
config_overrides: Optional[CognitoIdentityProviderClientConfig] = None,
user_attributes: Optional[AttributeListType] = None,
validation_data: Optional[AttributeListType] = None,
temporary_password: Optional[PasswordType] = None,
force_alias_creation: Optional[ForceAliasCreation] = None,
message_action: Optional[MessageActionType] = None,
desired_delivery_mediums: Optional[DeliveryMediumListType] = None,
client_metadata: Optional[ClientMetadataType] = None,
) -> AdminCreateUserResponse
Creates a new user in the specified user pool.
If MessageAction isn't set, the default is to send a welcome message via email or phone (SMS).
This message is based on a template that you configured in your call to create or update a user pool. This template includes your custom sign-up instructions and placeholders for user name and temporary password.
Alternatively, you can call AdminCreateUser with SUPPRESS for the MessageAction parameter, and Amazon Cognito won't send any email.
In either case, if the user has a password, they will be in the FORCE_CHANGE_PASSWORD state until they sign in and set their password. Your invitation message template must have the {####} password placeholder if your users have passwords. If your template doesn't have this placeholder, Amazon Cognito doesn't deliver the invitation message. In this case, you must update your message template and resend the password with a new AdminCreateUser request with a MessageAction value of RESEND.
This action might generate an SMS text message. Starting June 1, 2021, US telecom carriers require you to register an origination phone number before you can send SMS messages to US phone numbers. If you use SMS text messages in Amazon Cognito, you must register a phone number with Amazon Pinpoint. Amazon Cognito uses the registered number automatically. Otherwise, Amazon Cognito users who must receive SMS messages might not be able to sign up, activate their accounts, or sign in.
If you have never used SMS text messages with Amazon Cognito or any other Amazon Web Services service, Amazon Simple Notification Service might place your account in the SMS sandbox. In sandbox mode , you can send messages only to verified phone numbers. After you test your app while in the sandbox environment, you can move out of the sandbox and into production. For more information, see SMS message settings for Amazon Cognito user pools in the Amazon Cognito Developer Guide.
Amazon Cognito evaluates Identity and Access Management (IAM) policies in requests for this API operation. For this operation, you must use IAM credentials to authorize requests, and you must grant yourself the corresponding IAM permission in a policy.
Learn more
Parameters:
-
user_pool_id(UserPoolIdType) –The ID of the user pool where you want to create a user.
-
username(UsernameType) –The value that you want to set as the username sign-in attribute. The following conditions apply to the username parameter.
-
The username can't be a duplicate of another username in the same user pool.
-
You can't change the value of a username after you create it.
-
You can only provide a value if usernames are a valid sign-in attribute for your user pool. If your user pool only supports phone numbers or email addresses as sign-in attributes, Amazon Cognito automatically generates a username value. For more information, see Customizing sign-in attributes.
-
-
user_attributes(Optional[AttributeListType], default:None) –An array of name-value pairs that contain user attributes and attribute values to be set for the user to be created. You can create a user without specifying any attributes other than
Username. However, any attributes that you specify as required (when creating a user pool or in the Attributes tab of the console) either you should supply (in your call toAdminCreateUser) or the user should supply (when they sign up in response to your welcome message).For custom attributes, you must prepend the
custom:prefix to the attribute name.To send a message inviting the user to sign up, you must specify the user's email address or phone number. You can do this in your call to AdminCreateUser or in the Users tab of the Amazon Cognito console for managing your user pools.
You must also provide an email address or phone number when you expect the user to do passwordless sign-in with an email or SMS OTP. These attributes must be provided when passwordless options are the only available, or when you don't submit a
TemporaryPassword.In your
AdminCreateUserrequest, you can set theemail_verifiedandphone_number_verifiedattributes totrue. The following conditions apply:-
The email address where you want the user to receive their confirmation code and username. You must provide a value for
emailwhen you want to setemail_verifiedtotrue, or if you setEMAILin theDesiredDeliveryMediumsparameter. - phone_number
-
The phone number where you want the user to receive their confirmation code and username. You must provide a value for
phone_numberwhen you want to setphone_number_verifiedtotrue, or if you setSMSin theDesiredDeliveryMediumsparameter.
-
validation_data(Optional[AttributeListType], default:None) –Temporary user attributes that contribute to the outcomes of your pre sign-up Lambda trigger. This set of key-value pairs are for custom validation of information that you collect from your users but don't need to retain.
Your Lambda function can analyze this additional data and act on it. Your function can automatically confirm and verify select users or perform external API operations like logging user attributes and validation data to Amazon CloudWatch Logs.
For more information about the pre sign-up Lambda trigger, see Pre sign-up Lambda trigger.
-
temporary_password(Optional[PasswordType], default:None) –The user's temporary password. This password must conform to the password policy that you specified when you created the user pool.
The exception to the requirement for a password is when your user pool supports passwordless sign-in with email or SMS OTPs. To create a user with no password, omit this parameter or submit a blank value. You can only create a passwordless user when passwordless sign-in is available.
The temporary password is valid only once. To complete the Admin Create User flow, the user must enter the temporary password in the sign-in page, along with a new password to be used in all future sign-ins.
If you don't specify a value, Amazon Cognito generates one for you unless you have passwordless options active for your user pool.
The temporary password can only be used until the user account expiration limit that you set for your user pool. To reset the account after that time limit, you must call
AdminCreateUseragain and specifyRESENDfor theMessageActionparameter. -
force_alias_creation(Optional[ForceAliasCreation], default:None) –This parameter is used only if the
phone_number_verifiedoremail_verifiedattribute is set toTrue. Otherwise, it is ignored.If this parameter is set to
Trueand the phone number or email address specified in theUserAttributesparameter already exists as an alias with a different user, this request migrates the alias from the previous user to the newly-created user. The previous user will no longer be able to log in using that alias.If this parameter is set to
False, the API throws anAliasExistsExceptionerror if the alias already exists. The default value isFalse. -
message_action(Optional[MessageActionType], default:None) –Set to
RESENDto resend the invitation message to a user that already exists, and to reset the temporary-password duration with a new temporary password. Set toSUPPRESSto suppress sending the message. You can specify only one value. -
desired_delivery_mediums(Optional[DeliveryMediumListType], default:None) –Specify
EMAILif email will be used to send the welcome message. SpecifySMSif the phone number will be used. The default value isSMS. You can specify more than one value. -
client_metadata(Optional[ClientMetadataType], default:None) –A map of custom key-value pairs that you can provide as input for any custom workflows that this action triggers. You create custom workflows by assigning Lambda functions to user pool triggers.
When Amazon Cognito invokes any of these functions, it passes a JSON payload, which the function receives as input. This payload contains a
clientMetadataattribute that provides the data that you assigned to the ClientMetadata parameter in your request. In your function code, you can process theclientMetadatavalue to enhance your workflow for your specific needs.To review the Lambda trigger types that Amazon Cognito invokes at runtime with API requests, see Connecting API actions to Lambda triggers in the Amazon Cognito Developer Guide.
When you use the
ClientMetadataparameter, note that Amazon Cognito won't do the following:-
Store the
ClientMetadatavalue. This data is available only to Lambda triggers that are assigned to a user pool to support custom workflows. If your user pool configuration doesn't include triggers, theClientMetadataparameter serves no purpose. -
Validate the
ClientMetadatavalue. -
Encrypt the
ClientMetadatavalue. Don't send sensitive information in this parameter.
-
Raises:
-
CodeDeliveryFailureException–This exception is thrown when a verification code fails to deliver successfully.
-
InternalErrorException–This exception is thrown when Amazon Cognito encounters an internal error.
-
InvalidLambdaResponseException–This exception is thrown when Amazon Cognito encounters an invalid Lambda response.
-
InvalidParameterException–This exception is thrown when the Amazon Cognito service encounters an invalid parameter.
-
InvalidPasswordException–This exception is thrown when Amazon Cognito encounters an invalid password.
-
InvalidSmsRoleAccessPolicyException–This exception is returned when the role provided for SMS configuration doesn't have permission to publish using Amazon SNS.
-
InvalidSmsRoleTrustRelationshipException–This exception is thrown when the trust relationship is not valid for the role provided for SMS configuration. This can happen if you don't trust
cognito-idp.amazonaws.comor the external ID provided in the role does not match what is provided in the SMS configuration for the user pool. -
NotAuthorizedException–This exception is thrown when a user isn't authorized.
-
OperationNotEnabledException–This exception is thrown when an operation is not available in the current region or for the current user pool configuration. This can occur when attempting to perform operations that are not supported in secondary replica regions.
-
PreconditionNotMetException–This exception is thrown when a precondition is not met.
-
ResourceNotFoundException–This exception is thrown when the Amazon Cognito service can't find the requested resource.
-
TooManyRequestsException–This exception is thrown when the user has made too many requests for a given operation.
-
UnexpectedLambdaException–This exception is thrown when Amazon Cognito encounters an unexpected exception with Lambda.
-
UnsupportedUserStateException–The request failed because the user is in an unsupported state.
-
UserLambdaValidationException–This exception is thrown when the Amazon Cognito service encounters a user validation exception with the Lambda service.
-
UsernameExistsException–This exception is thrown when Amazon Cognito encounters a user name that already exists in the user pool.
-
UserNotFoundException–This exception is thrown when a user isn't found.
-
UnknownServiceError–The service returned an error code this client does not model.
Examples:
An AdminCreateUser request for for a test user named John. This request submits a value for all possible parameters for AdminCreateUser.
>>> client.admin_create_user(user_pool_id='us-east-1_EXAMPLE', username='testuser', desired_delivery_mediums=['SMS'], message_action='SUPPRESS', temporary_password='This-is-my-test-99!', user_attributes=[{'Name': 'name', 'Value': 'John'}, {'Name': 'phone_number', 'Value': '+12065551212'}, {'Name': 'email', 'Value': '[email protected]'}])
Source code in docs_src/capo_cognito_identity_provider/_services/cognito_identity_provider.py
821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 | |