AWS RDS (MySQL Example):
import pymysql
# Connect to the database
conn = pymysql.connect(
host='your-rds-endpoint',
user='username',
password='password',
database='your_database'
)
# Create a cursor object
cursor = conn.cursor()
# SQL query to insert data
insert_query = "INSERT INTO users (username, email) VALUES (%s, %s)"
# Data to insert
data = ('john_doe', '[email protected]')
# Execute the query
cursor.execute(insert_query, data)
# Commit changes
conn.commit()
# Close the connection
conn.close()
AWS DynamoDB Example:
import boto3
# Create a DynamoDB client
dynamodb = boto3.resource('dynamodb')
# Get the table
table = dynamodb.Table('users')
# Insert data into the table
table.put_item(
Item={
'id': 1,
'username': 'john_doe',
'email': '[email protected]'
}
)
print("Data inserted successfully!")