For Amplify Gen 2:
import { fetchAuthSession } from 'aws-amplify/auth';
const session = await fetchAuthSession();
console.log("id token", session);
There will be an identityId
property from the session
object returned.
https://docs.amplify.aws/react/build-a-backend/auth/connect-your-frontend/manage-user-sessions/