Search code examples
reactjsamazon-cognitoaws-amplifyamplifyjs

Manage Cognito credentials in Amplify config


I am using the Amplify package in my react client for the AWS Cognito authorization. To achieve that I need to configure the Cognito credentials in my client like in the below image.

config.js

The problem is I should not hard code the Cognito credentials because when I run my pipeline in a different environment a new Cognito user pool will be created with different credentials. So client has to fetch the Cognito credentials from some place like aws SSM and the authorization should work.

What is the best way to fetch the Cognito credentials for the client(Amplify configuration)?


Solution

  • From your question I assume you are not provisioning that Cognito within the Amplify application that you are writing. With that assumption I would suggest passing that Cognito pool id via an environment variable of platfrom you are running your build on.

    If you are using Amplify Console to build and provision your Amplify application, then you should put the environment variable there (in the Environment Variables section).

    However, if you are provisioning Cognito within your Amplify app (if you have done amplify add auth) that Cognito pool id should be present in the aws-exports.js file that Amplify generates.

    Hope this helps.