node.js – Setting credentials for CognitoUserPool using the new aws-sdk v3

This is my first web dev project, and I’m still learning my way around React, Node, Express, and AWS. I’m using Cognito for my auth provider, and I have this code from a tutorial that sets the credentials, region, and pool data for the user pool that I use when I execute an auth activity. The current code utilizes the aws-sdk v2 package that I’d like to future proof by moving to v3, however it’s unclear to me based on the instructions on the upgrade documentation what object I should be attaching the region and creds to, because I don’t currently have a client defined. (I don’t think?)
Here is current code:

const AmazonCognitoIdentity = require('amazon-cognito-identity-js')
const { CognitoIdentityCredentials} = require('aws-sdk')
const AWS = require('aws-sdk')


AWS.config.region = process.env.COGNITO_REGION
AWS.config.credentials = new CognitoIdentityCredentials({
    IdentityPoolId : process.env.COGNITO_IDENTITY_POOL_ID
})

const poolData = {
    UserPoolId : process.env.COGNITO_USER_POOL_ID,
    ClientId : process.env.COGNITO_CLIENT_ID
}

awsUserPool = new AmazonCognitoIdentity.CognitoUserPool(poolData)

module.exports = awsUserPool

This is the direction I feel like the documentation is telling me to go, but it feels like the new client object should be embedded somehow into the CognitoUserPool object somehow…

const { fromCognitoIdentity } = require("@aws-sdk/credential-providers")
const AmazonCognitoIdentity = require('amazon-cognito-identity-js')

const client = new ???({
    region: process.env.COGNITO_REGION,
    credentials: new CognitoIdentityCredentials({
        IdentityPoolId : process.env.COGNITO_IDENTITY_POOL_ID
    })
})

const poolData = {
    UserPoolId : process.env.COGNITO_USER_POOL_ID,
    ClientId : process.env.COGNITO_CLIENT_ID
}

awsUserPool = new AmazonCognitoIdentity.CognitoUserPool(poolData)

module.exports = awsUserPool

Read more here: Source link