Skip to content

Mutually exclusive statements in Cognito docs?

1

AdminCreateUser API states that pre sign up lambda can automatically confirm and verify users:

ValidationData 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.

Pre Sign Up Trigger doc explicitly says that it can't

Response parameters autoVerifyPhone, autoVerifyEmail and autoConfirmUser are ignored by Amazon Cognito when the pre sign-up Lambda function is triggered by the AdminCreateUser API.

Having confirmed thru testing that the latter is correct. What is the recommended solution for creating 'system' users? I am trying to use AWS::Cognito::UserPoolUser cloudformation resource and creates a user, but I see no way to confirm it automatically other than writing dubious post deployment scripts?

asked 2 years ago185 views

2 Answers
0

You're correct in identifying a discrepancy between the documentation for the AdminCreateUser API and the Pre Sign-Up Lambda trigger. Based on your testing and the more specific information in the Pre Sign-Up Lambda trigger documentation, it appears that the AdminCreateUser API description is not entirely accurate.

For creating 'system' users or automatically confirmed users through AWS CloudFormation, there are a few approaches you can consider:

  1. Use the AdminCreateUser API with "MessageAction" set to "SUPPRESS": This will create the user without sending a welcome message, and the user will be in a "FORCE_CHANGE_PASSWORD" state. You can then use the AdminSetUserPassword API to set a permanent password and confirm the user in one step.

  2. Use a Custom Resource in your CloudFormation template: Create a Lambda function that uses the Cognito API to create and confirm the user, then invoke this Lambda through a Custom Resource in your CloudFormation template.

  3. Use AWS CDK if possible: AWS CDK provides more flexibility and allows you to use custom resources more easily to perform these operations.

  4. Post-deployment scripts: While not ideal, as you mentioned, this is still an option if the above methods are not suitable for your use case.

  5. Consider using AWS Identity Center (formerly AWS SSO) for system users if they don't need to be in Cognito specifically.

Remember that automatically confirming users without verification can pose security risks, so ensure this aligns with your security requirements. If you need to create pre-verified system users, you might need to use a combination of the AdminCreateUser API and additional API calls to set the user's status as verified and confirmed.
Sources
Cognito Intermittent Error on Custom Lambda Trigger that redirects to login page solution at ConfirmSignUp. | AWS re:Post
Signing up and confirming user accounts - Amazon Cognito
Amazon Cognito Identity Provider examples using SDK for JavaScript (v3) - AWS SDK Code Examples

answered 2 years ago

0

You've identified a genuine discrepancy in the AWS documentation regarding the AdminCreateUser API and pre sign-up Lambda triggers. The Pre Sign-Up Lambda documentation is correct - the autoConfirmUser response is ignored when using AdminCreateUser.

For creating pre-confirmed system users with CloudFormation, you have these options:

Option 1: Use MessageAction Parameter (Recommended)

When using AdminCreateUser, set the MessageAction parameter to "SUPPRESS" to create a confirmed user without sending a welcome message:

Resources:
  SystemUser:
    Type: AWS::Cognito::UserPoolUser
    Properties:
      UserPoolId: !Ref UserPool
      Username: systemuser
      DesiredDeliveryMediums:
        - EMAIL
      MessageAction: SUPPRESS
      UserAttributes:
        - Name: email
          Value: system@example.com

This creates a confirmed user that can sign in with the temporary password.

Option 2: Use AdminConfirmSignUp in Custom Resource

Create a custom resource in CloudFormation that calls AdminConfirmSignUp after user creation:

Resources:
  ConfirmUserFunction:
    Type: AWS::Lambda::Function
    # Lambda function that calls AdminConfirmSignUp
  
  ConfirmUserCustomResource:
    Type: Custom::ConfirmUser
    Properties:
      ServiceToken: !GetAtt ConfirmUserFunction.Arn
      UserPoolId: !Ref UserPool
      Username: systemuser

Documentation

I recommend using Option 1 as it's simpler and doesn't require additional Lambda functions.

AWS

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.