AWS Databases
AWS Databases Overview
AWS offers various database services including Amazon RDS, Amazon DynamoDB, and Amazon Aurora. Below are the steps for setting up and using these services.
Setting Up Amazon RDS
1. **Launch an RDS instance**:
To create an RDS instance, use the AWS Management Console, CLI, or API.
Example CLI command to create an RDS instance:
aws rds create-db-instance --db-instance-identifier mydbinstance --db-instance-class db.t2.micro --engine mysql --allocated-storage 20 --master-username admin --master-user-password mypassword
2. **Connect to the RDS instance**:
After your instance is created, you can connect to it using the endpoint provided. For MySQL, use the following command:
mysql -h mydbinstance.cxjgihtxzmyr.us-east-1.rds.amazonaws.com -u admin -p
3. **List RDS instances**:
To view your RDS instances, run:
aws rds describe-db-instances
Setting Up Amazon DynamoDB
1. **Create a DynamoDB table**:
Use the following command to create a DynamoDB table:
aws dynamodb create-table --table-name MyTable --attribute-definitions AttributeName=ID,AttributeType=S --key-schema AttributeName=ID,KeyType=HASH --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5
2. **Put an item into DynamoDB**:
Example to insert an item into the DynamoDB table:
aws dynamodb put-item --table-name MyTable --item '{"ID": {"S": "123"}, "Name": {"S": "John Doe"}}'
3. **Scan DynamoDB table**:
To scan the contents of the DynamoDB table, use:
aws dynamodb scan --table-name MyTable
Setting Up Amazon Aurora
1. **Launch an Aurora DB Cluster**:
To create an Aurora DB cluster with MySQL engine, use the command:
aws rds create-db-cluster --db-cluster-identifier myauroracluster --engine aurora-mysql --master-username admin --master-user-password mypassword --vpc-security-group-ids sg-12345678
2. **Add an Aurora instance**:
Add a read replica or instance to the Aurora DB cluster:
aws rds create-db-instance --db-instance-identifier myaurora-instance --db-cluster-identifier myauroracluster --instance-class db.t3.medium --engine aurora-mysql
Helpful AWS Database Commands
- **List all RDS instances**:
aws rds describe-db-instances
- **Delete an RDS instance**:
aws rds delete-db-instance --db-instance-identifier mydbinstance --skip-final-snapshot
- **List all DynamoDB tables**:
aws dynamodb list-tables
- **Delete a DynamoDB table**:
aws dynamodb delete-table --table-name MyTable
- **List Aurora DB clusters**:
aws rds describe-db-clusters