By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
For AWS Solutions Architects who need to query exabytes of data without breaking the bank—or their sanity.
You’re a cloud engineer at a data-heavy company (e.g., ad-tech, IoT, or e-commerce). Your team dumps petabytes of raw logs, JSON files, and CSVs into S3—but analysts keep asking for ad-hoc queries. Your current Redshift cluster is slow, expensive, and running out of disk space. Meanwhile, your CFO is asking why your "cloud cost optimization" project hasn’t reduced the $50K/month Redshift bill.
This is where Redshift Spectrum, RA3 nodes, and distribution styles come in:- Redshift Spectrum lets you query data directly in S3 without loading it into Redshift. Think of it like a "virtual data lake" that offloads compute-heavy queries to a serverless engine.- RA3 nodes decouple compute and storage, so you pay only for the compute you use (like Fargate for Redshift). No more over-provisioning disk space.- Distribution styles determine how data is split across nodes. Choose wrong, and your queries crawl (or fail entirely).
Real-world scenario:You inherit a Redshift cluster with 10TB of data, 90% of which is cold (rarely queried). Your analysts need to join this with fresh S3 data (e.g., last 30 days of logs). Without Spectrum, you’d: 1. Load all 10TB into Redshift (expensive, slow).2. Write ETL jobs to move data between S3 and Redshift (operational overhead).3. Pray your cluster doesn’t run out of disk space during peak hours.
With Spectrum + RA3 + smart distribution:- Query only the hot data in Redshift (e.g., last 30 days).- Offload cold queries to Spectrum (S3).- Scale compute independently with RA3 nodes.- Cut costs by 60% while making queries 5x faster.
ra3.xlplus
user_id
DISTKEY(user_id)
users
countries
DISTSTYLE ALL
product_categories
DISTKEY
logs
AUTO: Let Redshift choose for you (usually EVEN or ALL).
EVEN
ALL
AUTO
Production insight: 90% of Redshift performance issues stem from bad distribution styles. If a query is slow, check STL_ALERT_EVENT_LOG for skew warnings.
STL_ALERT_EVENT_LOG
PRIMARY KEY
✅ AWS account with admin IAM permissions.✅ S3 bucket with sample data (e.g., s3://your-bucket/spectrum-demo/).✅ Redshift cluster (RA3 node type, e.g., ra3.xlplus).✅ AWS Glue Data Catalog (or Athena) for schema discovery.
s3://your-bucket/spectrum-demo/
Spectrum needs IAM roles to read S3. Skip this, and queries fail silently.
# Create an IAM policy for Spectrum aws iam create-policy \ --policy-name RedshiftSpectrumS3Access \ --policy-document '{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:GetObject", "s3:ListBucket" ], "Resource": [ "arn:aws:s3:::your-bucket", "arn:aws:s3:::your-bucket/*" ] }, { "Effect": "Allow", "Action": [ "glue:GetDatabase", "glue:GetTable", "glue:GetTables" ], "Resource": "*" } ] }' # Attach the policy to a new IAM role aws iam create-role \ --role-name RedshiftSpectrumRole \ --assume-role-policy-document '{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "redshift.amazonaws.com" }, "Action": "sts:AssumeRole" } ] }' aws iam attach-role-policy \ --role-name RedshiftSpectrumRole \ --policy-arn arn:aws:iam::YOUR_ACCOUNT_ID:policy/RedshiftSpectrumS3Access
Verify:
aws iam list-attached-role-policies --role-name RedshiftSpectrumRole
Expected output: The RedshiftSpectrumS3Access policy should appear.
RedshiftSpectrumS3Access
Connect to your Redshift cluster (e.g., via psql or the Redshift Query Editor).
psql
-- Create an external schema linked to Glue/Athena CREATE EXTERNAL SCHEMA spectrum_sales FROM DATA CATALOG DATABASE 'spectrum_db' -- This is a Glue database (create it first!) IAM_ROLE 'arn:aws:iam::YOUR_ACCOUNT_ID:role/RedshiftSpectrumRole' CREATE EXTERNAL DATABASE IF NOT EXISTS;
SELECT * FROM svv_external_schemas;
Expected output: Your spectrum_sales schema should appear.
spectrum_sales
Assume you have a Parquet file in S3 (s3://your-bucket/spectrum-demo/sales/).
s3://your-bucket/spectrum-demo/sales/
CREATE EXTERNAL TABLE spectrum_sales.sales_data ( sale_id BIGINT, product_id VARCHAR(50), sale_date DATE, amount DECIMAL(18,2) ) STORED AS PARQUET LOCATION 's3://your-bucket/spectrum-demo/sales/';
SELECT COUNT(*) FROM spectrum_sales.sales_data;
Expected output: The row count of your S3 data.
Now, join Redshift data with S3 data (the magic of Spectrum!).
-- Assume you have a local Redshift table 'products' SELECT p.product_name, SUM(s.amount) as total_sales FROM spectrum_sales.sales_data s JOIN products p ON s.product_id = p.product_id WHERE s.sale_date BETWEEN '2023-01-01' AND '2023-12-31' GROUP BY p.product_name ORDER BY total_sales DESC;
Production insight:- Spectrum queries are slower than Redshift (S3 latency). Cache results if analysts run the same query often.- Partition your S3 data (e.g., by sale_date) to reduce costs (Spectrum charges per GB scanned).
sale_date
-- Check current node type SELECT node_type FROM stv_slices; -- Resize to RA3 (requires cluster reboot) ALTER CLUSTER your-cluster-name RESIZE TO ra3.xlplus;
Expected downtime: ~15 minutes.
-- Example: Distribute 'sales' table by 'product_id' (common join key) CREATE TABLE sales ( sale_id BIGINT, product_id VARCHAR(50) DISTKEY, sale_date DATE, amount DECIMAL(18,2) ) SORTKEY (sale_date); -- Example: Replicate 'products' table to all nodes (small dimension table) CREATE TABLE products ( product_id VARCHAR(50) DISTKEY, product_name VARCHAR(100) ) DISTSTYLE ALL;
Verify distribution:
SELECT "table", "diststyle", "sortkey1" FROM svv_table_info WHERE "schema" = 'public';
Expected output:
table | diststyle | sortkey1 ---------+-----------+---------- sales | KEY | sale_date products | ALL | (none)
*
year/month/day
sql CREATE EXTERNAL TABLE spectrum_sales.sales_partitioned ( sale_id BIGINT, product_id VARCHAR(50), amount DECIMAL(18,2) ) PARTITIONED BY (sale_date DATE) STORED AS PARQUET LOCATION 's3://your-bucket/spectrum-demo/sales/';
Redshift Spectrum
Environment=Prod
Team=Analytics
sql -- Find slow Spectrum queries SELECT query, elapsed/1000000 as elapsed_sec, cpu_time/1000000 as cpu_sec FROM stl_query WHERE query LIKE '%spectrum%' ORDER BY elapsed DESC;
CPUUtilization
DatabaseConnections
date
region
PARTITIONED BY
Skew in distribution
AccessDenied
SELECT * FROM svv_external_schemas
❌ DC2 (legacy, fixed storage).
"How do you query data in S3 without loading it into Redshift?"
❌ Athena (standalone, not integrated with Redshift).
"Which distribution style replicates a table to all nodes?"
❌ DISTKEY (distributes by column).
"You need to join a 10TB Redshift table with 1TB of S3 data. How do you optimize costs?"
You have: - A Redshift table users (10M rows, DISTKEY(user_id)).- An S3 bucket with orders data (Parquet, partitioned by order_date).
orders
order_date
Task: Write a query to find users who placed >5 orders in 2023, joining users (Redshift) with orders (S3).
-- Create external table for orders CREATE EXTERNAL TABLE spectrum.orders ( order_id BIGINT, user_id VARCHAR(50), order_date DATE, amount DECIMAL(18,2) ) PARTITIONED BY (order_date DATE) STORED AS PARQUET LOCATION 's3://your-bucket/orders/'; -- Query (joins Redshift 'users' with S3 'orders') SELECT u.user_id, u.name, COUNT(o.order_id) as order_count FROM users u JOIN spectrum.orders o ON u.user_id = o.user_id WHERE o.order_date BETWEEN '2023-01-01' AND '2023-12-31' GROUP BY u.user_id, u.name HAVING COUNT(o.order_id) > 5;
Why it works:- Spectrum queries S3 without loading data into Redshift.- Partitioning (order_date) reduces S3 scan costs.- DISTKEY(user_id) ensures the join is co-located (no data shuffling).
CREATE EXTERNAL SCHEMA
IAM_ROLE
DISTKEY(column)
RA3 nodes
WLM
SSE-S3
ra3.4xlarge
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.