amplify-js: ClientMetadata provided to Auth.signUp is not available in post confirmation lambda

Describe the bug According to docs at: https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-post-confirmation.html a clientMetadata provided to Auth.signUp method should be available in post confirmation lambda. Unfortunately it’s not. (there’s no clientMetadata key in request)

To Reproduce Steps to reproduce the behavior:

  1. Call Auth.signUp with clientMetadata
const result = await Auth.signUp({
                username: "username",
                password: "P@ssw0rd",
                attributes: {
                    given_name: "givenname",
                    family_name: "lastname",
                    email: "email"
                },
                clientMetadata: {
                    "foo": "bar",
                }
          });
  1. Log event in post confirmation lambda
exports.handler = async (event, context, callback) => {
   console.log(event);
   console.log(event.request.clientMetadata ? "It's fine" : "There's no clientMetadata");
}

**Expected behavior**
I'd expect that clientMetadata passed to `Auth.signUp` method is available in post confirmation lambda as above docs states.  

<details>
  <summary><strong>Environment</strong></summary>

<!-- Please run the following command inside your project and copy/paste the output into the codeblock: -->

npx envinfo --system --binaries --browsers --npmPackages --npmGlobalPackages


  System:
    OS: Windows 10 10.0.18362
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
    Memory: 10.20 GB / 31.72 GB
  Binaries:
    Node: 12.13.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.19.0 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.12.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: 44.18362.449.0
    Internet Explorer: 11.0.18362.1
  npmPackages:
    aws-amplify: ^1.2.4 => 1.2.4
    aws-amplify-react: ^2.5.4 => 2.5.4
    react: ^16.12.0 => 16.12.0
    react-dom: ^16.12.0 => 16.12.0
    react-router-dom: ^5.1.2 => 5.1.2
    react-scripts: 3.2.0 => 3.2.0
    typescript: 3.7.2 => 3.7.2
</details>

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 6
  • Comments: 16 (5 by maintainers)

Most upvoted comments

SignUp still doesn’t pass clientMetadata to post confirmation trigger lambda when documentation says it should:

clientMetadata One or more key-value pairs that you can provide as custom input to the Lambda function that you specify for the post confirmation trigger. You can pass this data to your Lambda function by using the ClientMetadata parameter in the following API actions: AdminConfirmSignUp, ConfirmForgotPassword, ConfirmSignUp, and SignUp. https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-post-confirmation.html#cognito-user-pools-lambda-trigger-syntax-post-confirmation

@haverchuck Any news from Cognito? Is there a way to track this issue with them?

@haverchuck Sorry, but it’s not what the documentation says about clientMetadata parameter: https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-post-confirmation.html#cognito-user-pools-lambda-trigger-syntax-post-confirmation-request

You can pass this data to your Lambda function by using the ClientMetadata parameter in the following API actions: AdminConfirmSignUp, ConfirmForgotPassword, ConfirmSignUp, and SignUp.

It explicitly mentions sign up action, so I’d argue that it should be possible or the documentation has to be fixed.

@haverchuck Sorry if I misunderstand something, but the documentation is not about arbitrary lambda from the workflow. It’s specific about Post Confirmation Lambda and Post Confirmation Request Parameters and explicitly says that clientMetadata parameter can be passed by the SingUp action. I understand that it might not work, but then you should remove SignUp from the actions mentioned in that paragraph.

@krlm I am working on getting clarification from the Cognito team.

@krlm The paragraph you’ve quoted is true - you can pass client metadata to the triggers that are called by those API actions.

However, what you’ve described is a case in which you are expecting to see clientMetadata getting passed from the SignUp API action to the Post Confirmation trigger. This won’t happen, since the SignUp API action does not call the Post Confirmation trigger. The ConfirmSignUp API action is what calls the Post Confirmation trigger. If you want to get data to the Post Confirmation trigger, you will need to pass it to Auth.confirmSignUp (as part of the options parameter).

@haverchuck This issue seems to have not been addressed. Are there any updates from the cognito auth team? @krlm Did you ever get this to work?

I am calling Auth.signUp with clientMetaData as a parameter, and setting event.response.autoConfirmUser to true inside of the Pre Sign-up lambda. When I check the logs for the Pre Sign-up lambda clientMetaData is present inside of event.request but then when I check the Post Confirmation lambda clientMetaData is missing.

The documentation still says clientMetadata can be passed to the Post Confirmation lambda using Auth.signUp and doesn’t give any special instructions for how to do that which would lead me to believe it should just work.

I have this same issue. My use case is that I need to send data to the Post confirmation lambda function that I don’t want to store as a user attribute. So how else do I pass this information? I’m not seeing the clientMetadata in the event data coming into lambda, please advise on possible solutions or workarounds where I can send data to this function. Thank you. @haverchuck @thomaswr

It also looks like the docs haven’t changed.

FWIW, we’ve discovered that if you’re doing a phone/email validation as part of your registration process and use the confirmRegistration() method then sending the clientMetadata with that confirmation call does surface it in the postConfirmation trigger.

@haverchuck You mean Pre Sign-up trigger with autoConfirmUser parameter? Then, I think, it should be clarified in the cited docs, otherwise it’s grossly misleading.

@krlm I have spoken to the Cognito team. My understanding is that if your SignUp trigger uses the API to mark the user as confirmed, THEN the client metadata that was passed to the SignUp trigger will be passed directly to the PostConfirmation trigger (so it’s kind of a specialized use case). In other cases, you will need to pass the clientMetadata through the Auth.confirmSignUp method.