I'm trying to retrieve all dynamodb tables with boto3. Using AWS CLI with:
aws dynamodb list-tables
It works:
{
"TableNames": [
"table_name1",
"table_name2",
...
}
But with boto3, It does not retrieve them. If I test another service with boto3 like S3 to retrieve buckets, it works. So it is not a connection/rights problem.
Here's my simple code:
import boto3
AWS_ACCESS_KEY_ID = "xxx"
AWS_SECRET_ACCESS_KEY = "xxx"
AWS_SESSION_TOKEN = "xxx"
AWS_REGION_NAME = 'us-east-1'
session = boto3.Session(
aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
aws_session_token=AWS_SESSION_TOKEN,
region_name=AWS_REGION_NAME
)
available_services = session.get_available_services()
print("Available services:")
print(available_services)
s3_client = session.client('s3')
print("===== S3 =====")
buckets = [bucket['Name'] for bucket in s3_client.list_buckets()['Buckets']]
print(f"Buckets {len(buckets)}")
dynamodb_client = session.client('dynamodb')
print("===== DynamoDB =====")
table_names = dynamodb_client.list_tables()['TableNames']
print(f"Tables {len(table_names)}")
print(table_names)
And the output
Available services:
['accessanalyzer', 'account', ...'dynamodb'...'s3'...]
===== S3 =====
Buckets 150
===== DynamoDB =====
Tables 2
['LimitMonitor-SummaryDDB-1951SZYTWET87', 'LimitMonitor-SummaryDDB-FEBN4S1LC0OF']
So with aws cli, it lists more than my hundred tables, with boto3, only 2: LimitMonitor-...
, I don't know what they are.
Is something wrong using boto3 dynamodb client?
My bad problem solved. It concerns AWS_REGION_NAME which was set to 'us-east-1' instead of 'eu-central-1'. I can see buckets as it's global.