title: How to turn an CognitoAuth auth object into AWS-SDK credentials
body: <p>I have a cognito userpool and i can successfully log into my app with the following code:</p>
  <pre><code>const authData = {
          ClientId : '2222222222222', // Your client id here
          AppWebDomain : '1111111111.auth.us-east-1.amazoncognito.com',
          TokenScopesArray : ['openid'],
          RedirectUriSignIn : 'https://app.domain.com',
          RedirectUriSignOut : 'https://app.domain.com'
      };
      const CognitoAuth = AmazonCognitoIdentity.CognitoAuth;
  
      const auth = new CognitoAuth(authData);
  
  
  
      auth.userhandler = {
          /**onSuccess: &lt;TODO: your onSuccess callback here&gt;,
           onFailure: &lt;TODO: your onFailure callback here&gt;*/
  
          onSuccess: function(result: any) {
              console.log(&quot;COGNITO SUCCESS!&quot;);
              console.log(result);
          },
          onFailure: function(err: any) {
              console.log(&quot;COGNITO FAIL!&quot;);
              console.log(err);
          }
      };
  
      auth.getSession();
  
      const curUrl = window.location.href;
      auth.parseCognitoWebResponse(curUrl);
  </code></pre>
  <p>I now have an auth object that I would like to parlay into some sort of credentials for the aws-sdk that i have so that i can list items into an S3 bucket, assuming the correct policies in my attached roles.</p>
  <p>something like this, but realize this doesn't work:</p>
  <pre><code>AWS.config.credentials = auth.toCredentials();  //&lt;== hoping for magic
  const s3 = new AWS.S3();
  s3.listObjectsV2(listObjectsV2Params, function(err: any, data: any) {
          if (err) console.log(err, err.stack); // an error occurred
          else     console.log(data.Contents[0]);           // successful response
      });
  </code></pre>
  <p>Is this possible, and if so how do i do that?</p>
  <h2>UDPATE</h2>
  <p>Accepted answer worked and was a big help, adding some additions for clarity along the lines of trouble I ran into.</p>
  <pre><code>const creds = new AWS.CognitoIdentityCredentials({
                  IdentityPoolId: 'us-east-1:b111111-1111-1111-1111-1111111',  // &lt;-- This is in your Federated Identity if you have that set up, you have to &quot;edit&quot; the identity pool to get it, logging into cognito its a different screen.
                  Logins: {
                      &quot;cognito-idp.us-east-1.amazonaws.com/us-east-1_BBBB1BBBBV2B&quot;: result.idToken.jwtToken  // &lt;- this login [POOL ID] is not the pool ARN, you need it in this format.
                  }
              });
  </code></pre>
  <p><a href="http://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-integrating-user-pools-with-identity-pools.html" rel="nofollow noreferrer">this link helped me.</a></p>