title: How to get AWSCredentials given a AWS Cognito access_token
body: <p>In an android app, I receive a JWT access_token from <code>http://&lt;domain&gt;.auth.&lt;region&gt;.amazoncognito.com/login</code> once the user is done authenticating to a Cognito User Pool. That User Pool is linked to a Cognito Identity Pool.</p>
  
  <p>What API should I call with that access_token to get an <code>AWSCredentials</code> object.</p>
  
  <p>The closest one I found would be <a href="https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRoleWithWebIdentity.html" rel="noreferrer">AssumeRoleWithWebIdentity</a>, but that is an STS API, and some of what I've read on the web seems to recommend developers not use STS directly but rely on Cognito.</p>
  
  <p>Moreover, I do not expect the API I need to require specifying a role name. Cognito Identity Pools are already configured to give authenticated users a specific role. And AssumeRoleWithWebIdentity takes a role name as input to the API. Hence that does not look like right.</p>
  
  <p>I've looked at <a href="https://docs.aws.amazon.com/cognitoidentity/latest/APIReference/Welcome.html" rel="noreferrer">Cognito Identity Pool API Reference</a>, and can't find an API that takes access_token and return AWS credentials. </p>
  
  <p><strong>UPDATE:</strong>
  The following answer which uses <code>GetCredentialsForIdentity</code> throws <code>ResourceNotFoundException</code> saying it cannot find the specified IdentityId.</p>
  
  <pre><code>string access_token = ...
  var jwtAccessToken = System.IdentityModel.Tokens.Jwt.JwtSecurityToken(access_token);
  
  var client = new AmazonCognitoIdentityClient(new AnonymousAWSCredentials(),REGION);
  
  var response = await client.GetCredentialsForIdentityAsync(new GetCredentialsForIdentityRequest
  {
      IdentityId=String.Format("{0}:{1}", REGION, jwtAccessToken.id),
      Logins=new Dictionary&lt;string,string&gt; 
      { 
          {String.Format("cognito-idp.{0}.amazonaws.com/{1}", REGION, USER_POOL_ID),
           access_token}
      }
  });
  </code></pre>