Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError when creating new CognitoIdentityClient #2582

Closed
jzybert opened this issue Jul 14, 2021 · 3 comments · Fixed by #2601
Closed

TypeError when creating new CognitoIdentityClient #2582

jzybert opened this issue Jul 14, 2021 · 3 comments · Fixed by #2601
Labels
bug This issue is a bug. duplicate This issue is a duplicate.

Comments

@jzybert
Copy link

jzybert commented Jul 14, 2021

Describe the bug

I am trying to create an S3Client object in my NodeJS service that will use credentials from my Cognito Identity Pool. I've followed the tutorial here: https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/loading-browser-credentials-cognito.html. However, when I run that code, I see TypeError: Object(...) is not a function.

It comes from the new CognitoIdentityClient({region: REGION}) line.

The stack trace:

TypeError: Object(...) is not a function
    at defaultProvider (...)
    at Object.credentialDefaultProvider (...)
    at resolveAwsAuthConfig (...)
    at new CognitoIdentityClient (...)

Your environment

macOS Catalina v10.15.7, MacBook Pro (16-inch, 2019)

Running this inside the WebStorm IDE from JetBrains.

SDK version number

"@aws-sdk/client-cognito-identity": "^3.20.0",
"@aws-sdk/client-s3": "^3.20.0",
"@aws-sdk/credential-provider-cognito-identity": "^3.20.0",

Is the issue in the browser/Node.js/ReactNative?

Node.js

Details of the browser/Node.js/ReactNative version

Paste output of npx envinfo --browsers or node -v or react-native -v

node -v
v12.19.1

Steps to reproduce

const {S3Client} = require("@aws-sdk/client-s3");
const {CognitoIdentityClient} = require("@aws-sdk/client-cognito-identity");
const {fromCognitoIdentityPool} = require("@aws-sdk/credential-provider-cognito-identity");

// AWS Constants
const REGION = 'us-east-1';
const IDENTITY_POOL_ID = 'IDENTITY_POOL_ID'; // removing actual ID
const USER_POOL_ID = 'USER_POOL_ID'; //removing actual ID
const COGNITO_ID = `cognito-idp.${REGION}.amazonaws.com/${USER_POOL_ID}`;

export async function listS3Files(token) {
    try {
        const loginData = {
            [COGNITO_ID]: token
        };
        const s3Client = new S3Client({
            region: REGION,
            credentials: fromCognitoIdentityPool({
                client: new CognitoIdentityClient({region: REGION}),
                identityPoolId: IDENTITY_POOL_ID,
                logins: {
                    ...loginData
                }
            })
        });
    } catch (error) {
        console.log(error);
        throw error;
    }
}

Observed behavior

Trying to create an S3Client using the v3 tutorial results in a TypeError being thrown when the CognitoIdentityClient is created.

Expected behavior

No TypeError should be thrown. I should be able to create the S3Client with no issues.

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

Add any other context about the problem here.

@jzybert jzybert added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 14, 2021
@AllanZhengYP
Copy link
Contributor

Hi @jzybert

I cannot reproduce the issue, can you point out which line in source code is throwing the error? It'll be the helpful for us if you can create a reproduction repo so we can reproduce the issue from clean slate.

@AllanZhengYP
Copy link
Contributor

Per offline discussion, this issue is dupilcated to #2587. I will close this report and track the issue on the other ticket.

@AllanZhengYP AllanZhengYP added duplicate This issue is a duplicate. and removed needs-triage This issue or PR still needs to be triaged. labels Jul 19, 2021
@github-actions
Copy link

github-actions bot commented Aug 3, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug. duplicate This issue is a duplicate.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants