El SDK (Software Development Kit) de AWS te permite interactuar con DynamoDB desde distintos lenguajes de programación como Python, JavaScript, Java, Go, etc.
Aquí te explico cómo usarlo con el lenguaje más común: Python, usando el paquete boto3.
🧰 1. Instalación del SDK para Python (boto3)
pip install boto3
🔐 2. Configurar credenciales de AWS
Puedes hacerlo con el siguiente comando:
aws configure
Esto guarda tus credenciales de acceso (Access Key, Secret Key, región, y formato) en ~/.aws/credentials.
📁 3. Crear una tabla DynamoDB con SDK (Python)
import boto3
dynamodb = boto3.resource('dynamodb')
table = dynamodb.create_table(
TableName='Estudiantes',
KeySchema=[
{
'AttributeName': 'EstudianteId',
'KeyType': 'HASH' # Clave primaria
}
],
AttributeDefinitions=[
{
'AttributeName': 'EstudianteId',
'AttributeType': 'N'
}
],
ProvisionedThroughput={
'ReadCapacityUnits': 5,
'WriteCapacityUnits': 5
}
)
print("Esperando a que la tabla esté disponible...")
table.wait_until_exists()
print("Tabla creada con éxito")
📥 4. Insertar un ítem en la tabla
table = dynamodb.Table('Estudiantes')
table.put_item(
Item={
'EstudianteId': 1,
'Nombre': 'Mario Vargas',
'Curso': 'Ingeniería'
}
)
📤 5. Consultar un ítem
response = table.get_item(
Key={
'EstudianteId': 1
}
)
print(response['Item'])
🧹 6. Eliminar una tabla
table = dynamodb.Table('Estudiantes')
table.delete()