title: Amazon AWS Cognito and Python Boto3 to establish AWS connection and upload file to Bucket
body: <p>I'm trying to use the AWS cognito service to authenticate and upload a file. I have been provided my regionType, identityPool, AWS account ID, and UnAuthRole. I also know the production and development bucket names.</p>
  
  <p>I think I am setting the AWS Access Key and AWS Secret Key... I want to authenticate with cognito and use the results to allow me to do an bucket listing and later a file upload.</p>
  
  <p>What am I doing wrong? How can I use the cognito id to establish an S3 connection?</p>
  
  <p>Here is my code and the resulting error:</p>
  
  <pre><code>#!/usr/bin/python
  
  import boto3
  import boto
  #boto.set_stream_logger('foo')
  import json
  client = boto3.client('cognito-identity','us-east-1')
  resp =  client.get_id(AccountId='&lt;ACCNTID&gt;',IdentityPoolId='&lt;IDPOOLID&gt;')
  print "\nIdentity ID: %s"%(resp['IdentityId'])
  print "\nRequest ID: %s"%(resp['ResponseMetadata']['RequestId'])
  resp = client.get_open_id_token(IdentityId=resp['IdentityId'])
  token = resp['Token']
  print "\nToken: %s"%(token)
  print "\nIdentity ID: %s"%(resp['IdentityId'])
  resp = client.get_credentials_for_identity(IdentityId=resp['IdentityId'])
  secretKey = resp['Credentials']['SecretKey']
  accessKey = resp['Credentials']['AccessKeyId']
  print "\nSecretKey: %s"%(secretKey)
  print "\nAccessKey ID: %s"%(accessKey)
  print resp
  conn = boto.connect_s3(aws_access_key_id=accessKey,aws_secret_access_key=secretKey,debug=0)
  print "\nConnection: %s"%(conn)
  for bucket in conn.get_all_buckets():
      print bucket.name
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>   Traceback (most recent call last):
    File "./test.py", line 32, in &lt;module&gt;
      for bucket in conn.get_all_buckets():
    File "/usr/local/lib/python2.7/dist-packages/boto/s3/connection.py", line 440, in get_all_buckets
      response.status, response.reason, body)
  boto.exception.S3ResponseError: S3ResponseError: 403 Forbidden
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Error&gt;&lt;Code&gt;InvalidAccessKeyId&lt;/Code&gt;&lt;Message&gt;The AWS Access Key Id you provided does not exist in our records.&lt;/Message&gt;&lt;AWSAccessKeyId&gt;ASIAILXMPZEMJAVZN7TQ&lt;/AWSAccessKeyId&gt;&lt;RequestId&gt;10631ACFF95610DD&lt;/RequestId&gt;&lt;HostId&gt;PGWDRBmhLjjv8Ast8v6kVHOG3xR8erJRV2ob3/2RmqHXwrg8HCZV578YsNLaoL24Hknr+nh033U=&lt;/HostId&gt;&lt;/Error&gt;
  </code></pre>
  
  <p>This corresponding iOS code works fine:</p>
  
  <pre><code>AWSCognitoCredentialsProvider *credentialsProvider =
  [AWSCognitoCredentialsProvider credentialsWithRegionType:awsCognitoRegionType
                                                 accountId:awsAccountId
                                            identityPoolId:awsCognitoIdentityPool
                                             unauthRoleArn:unauthRoleArn
                                                    authRoleArn:nil];
  
  AWSServiceConfiguration *configuration = [AWSServiceConfiguration configurationWithRegion:awsCognitoRegionType
                                                                        credentialsProvider:credentialsProvider];
  
  ....
  
  AWSS3TransferManagerUploadRequest *uploadRequest = [AWSS3TransferManagerUploadRequest new];
  uploadRequest.bucket = [ELEEnvironment currentEnvironment].userDataS3Bucket;
  uploadRequest.key = key;
  uploadRequest.body = uploadFileURL;
  [[self uploadTask:uploadRequest] continueWithExecutor:[BFExecutor mainThreadExecutor]...
  </code></pre>
  
  <p>Thanks for any help!</p>