2

I'm new to AWS and boto 3 Python SDK. I configured the Access Key ID, Secret Access Key and the region name through AWS CLI.

import boto3

client = boto3.client('cognito-idp')

response = client.admin_get_user(
    UserPoolId='us-east-2_hJpikme9T',
    Username='wasdkiller'
)

Here is my user pool details,

connection pool details

I provided the correct UserPoolId, but when I run above code sample I got below error for every functions in CognitoIdentityProvider, for an example I used admin_get_user(**kwargs).

ResourceNotFoundException: An error occurred (ResourceNotFoundException) when calling the AdminGetUser operation: User pool us-east-2_hJpikme9T does not exist.
Kushan Gunasekera
  • 7,268
  • 6
  • 44
  • 58

2 Answers2

4

We can provide more arguments in boto3.client(*args, **kwargs) other than the service_name(the default parameter). As you can see client() in Session Reference, we can provide aws_access_key_id, aws_secret_access_key, and region_name without using AWS CLI.

If you are using default parameters such as you already given through AWS CLI that's fine, you don't need to mention aws_access_key_id or aws_secret_access_key when calling boto3.client(). But I don't know for some reason you have to mention your region_name which is you already given through AWS CLI when calling boto3.client().

client = boto3.client('cognito-idp', region_name='us-east-2')

In this way I clear out my above problem. But still I don't know why we have to specially mention the region_name argument when calling boto3.client(), please update this answer or comment below if you know anything about it.

Kushan Gunasekera
  • 7,268
  • 6
  • 44
  • 58
  • 3
    You needed to manually specify the region because by default, Boto3 takes the region mentioned in the ~./aws/credentials file. In your case, it would be something other than us-east-2. – Arka Mukherjee Jun 13 '19 at 07:26
  • 1
    oh now I got it thanks to you @ArkaMukherjee, in my `~/.aws/credentials` file there is no `region` variable. But I can see it's in the `~/.aws/config`. – Kushan Gunasekera Jun 13 '19 at 07:41
1

I had the same error. Another option is to create the User Pool in region us-east-1. I did that and cognito identity was authenticated successfully.

CloudArch
  • 291
  • 2
  • 3