forked from awsdocs/aws-doc-sdk-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello_dynamodb.py
More file actions
33 lines (23 loc) · 965 Bytes
/
hello_dynamodb.py
File metadata and controls
33 lines (23 loc) · 965 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
# snippet-start:[python.dynamodb.hello_dynamodb]
import boto3
# Create a DynamoDB client using the default credentials and region
dynamodb = boto3.client("dynamodb")
# Initialize a paginator for the list_tables operation
paginator = dynamodb.get_paginator("list_tables")
# Create a PageIterator from the paginator
page_iterator = paginator.paginate(Limit=10)
# List the tables in the current AWS account
print("Here are the DynamoDB tables in your account:")
# Use pagination to list all tables
table_names = []
for page in page_iterator:
for table_name in page.get("TableNames", []):
print(f"- {table_name}")
table_names.append(table_name)
if not table_names:
print("You don't have any DynamoDB tables in your account.")
else:
print(f"\nFound {len(table_names)} tables.")
# snippet-end:[python.dynamodb.hello_dynamodb]