AWS — Redshift
What is Redshift?
Fully managed petabyte-scale data warehouse.
Create cluster
aws redshift create-cluster \
--cluster-identifier my-cluster \
--node-type dc2.large \
--master-username admin \
--master-user-password password123 \
--number-of-nodes 2
Connect
import psycopg2
conn = psycopg2.connect(
host='my-cluster.xxxx.us-east-1.redshift.amazonaws.com',
port=5439,
database='dev',
user='admin',
password='password123'
)
Load data
COPY table_name
FROM 's3://my-bucket/data/'
IAM_ROLE 'arn:aws:iam::123456789:role/redshift-role'
FORMAT AS PARQUET;
Query
SELECT column1, COUNT(*)
FROM table_name
GROUP BY column1
ORDER BY COUNT(*) DESC;
Spectrum
-- Query S3 data directly
SELECT * FROM external_schema.my_table
WHERE date = '2024-01-01';
Best practices
- Use sort keys
- Use distribution keys
- Vacuum regularly
- Use workloads management
Mini Practice
- Create a cluster
- Load data from S3
- Run analytical queries
- Use Spectrum for S3 data
Up Next
Continue with Step Functions - Workflows.
Related Topics
Frequently Asked Questions about Redshift
What is Redshift in AWS?
Redshift is a fundamental concept in AWS. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Redshift?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Redshift.
Why is Redshift important in AWS?
Redshift is essential for AWS development. Understanding this concept will help you write better code and solve real-world problems more effectively.