Analytics on AWS — Amazon Redshift
Tags: aws, cloud, analytics, redshift
Published: 2023-03-13 07:00:01

![Architecture](https://cdn-images-1.medium.com/max/2254/1*RIhxlddK0yP0hVWHUiYAag.png)

**NOTE**: This article has associated with my article about [Analytics on AWS — AWS Glue](https://dev.to/budionosan/analytics-on-aws-aws-glue-3341).

Hello everyone. I am Budi want to explain about [Amazon Redshift](https://aws.amazon.com/redshift/). **Amazon Redshift** is an AWS service that serves data warehouses using SQL.

Amazon Redshift has several features like **Redshift ML** (create, train, and deploy machine learning models using SQL), **Redshift Serverless** (data warehouse without creating cluster/server), **Redshift Streaming Ingestion** (ingest real-time data with Amazon Kinesis), and many more.

Amazon Redshift also can connect to SQL Workbench, business intelligence tools like Tableau, Amazon Quicksight, and many more, and ETL tools like AWS Glue with JDBC or ODBC drivers.

Before creating the Redshift cluster, the first created IAM role for Redshift. Go to Security, Identity, & Compliance section, and search IAM. Next click Roles. Click Create a role in IAM Roles.

![](https://cdn-images-1.medium.com/max/2000/1*Vm9DIMbj3XQBiuU3KqIv_Q.jpeg)

![](https://cdn-images-1.medium.com/max/2000/1*YAx40ab_j0qPwCSwt7kV9g.jpeg)

Choose AWS service then chooses Redshift — Customizable. Click Next.

![](https://cdn-images-1.medium.com/max/2000/1*_ar0Zz74hOzh-qpZE5ui1Q.jpeg)

![](https://cdn-images-1.medium.com/max/2000/1*pq67MkNG5kQBCfVALsDGzw.jpeg)

Add permissions to IAM role for Redshift. Filter **Amazon S3,** **Amazon Redshift** and click Next.

![](https://cdn-images-1.medium.com/max/2000/1*7g997ai24uLs8XpdGYd7TQ.jpeg)

![](https://cdn-images-1.medium.com/max/2000/1*vvy7KTxAPfY2vtb93MNa-A.jpeg)

![](https://cdn-images-1.medium.com/max/2000/1*G24_IJViAw-_pFrg_OT0kw.jpeg)

Fill in the IAM role name and click Create role.

![](https://cdn-images-1.medium.com/max/2000/1*o1pUwQ860LXQ6GJvpij9Fw.jpeg)

![](https://cdn-images-1.medium.com/max/2000/1*kw927mCnYZrrexoHOGOv7A.jpeg)

After created IAM role for Redshift, you can see permissions policies that needed.

![](https://cdn-images-1.medium.com/max/2446/1*dbh2Jr2Kd0F8j4jk5vBzQw.jpeg)

![](https://cdn-images-1.medium.com/max/2442/1*gGSr9LLvq1iQesG7EJaEXw.jpeg)

Go to Amazon Redshift. Before creating a Redshift cluster, create Redshift subnet groups to connect to VPC. Click subnet groups. Click cluster subnet group.

![](https://cdn-images-1.medium.com/max/2000/1*YX9RS0DU5RAE0keOsh2ljw.jpeg)

![](https://cdn-images-1.medium.com/max/2024/1*kVhKqMgRftpDhYo8VE4slQ.jpeg)

Fill in the subnet group name and description. Choose VPC for Redshift cluster. You can create VPC with [this link](https://dev.to/budionosan/networking-on-aws-amazon-virtual-private-cloud-vpc-4phd).

![](https://cdn-images-1.medium.com/max/2000/1*ndXvwLa3QF376BOgHH258w.jpeg)

![](https://cdn-images-1.medium.com/max/2000/1*CLbGVvtE_bwXo_Q57hmezg.jpeg)

Click **Add all the subnets for this VPC**. My VPC have 3 subnets. Then click create cluster subnet group.

![](https://cdn-images-1.medium.com/max/2000/1*WXI7sHbj9HDoJOy0IFdJ-g.jpeg)

![](https://cdn-images-1.medium.com/max/2000/1*h30jB1loFhROrHVxmxGufA.jpeg)

After creating a subnet group, the subnet group has connected to VPC that can be used to create a Redshift cluster.

![](https://cdn-images-1.medium.com/max/2544/1*xfaDOYX7ukn33yXjGUCjIA.jpeg)

Click provisioned clusters dashboard, click Create cluster. I want try Redshift Serverless but coming soon.

![](https://cdn-images-1.medium.com/max/2000/1*WvFUdtm16-BCiyKJ3cbTeQ.jpeg)

Fill in the cluster name. If you choose free trial, you cannot edit settings VPC and many more. Choose production.

![](https://cdn-images-1.medium.com/max/2000/1*JRcLHODorzMo69VZ8DUnXQ.jpeg)

Choose dc2.large for the node type in the Redshift cluster. Btw, dc2.large is free for 2 months if you try the new Amazon Redshift.

![](https://cdn-images-1.medium.com/max/2000/1*Tpk7aKttBQWtgAEbherFkQ.jpeg)

Fill in the username and password for login when want query in Redshift cluster.

![](https://cdn-images-1.medium.com/max/2000/1*EMR-j0qxSSZ2uAgg0aQFEQ.jpeg)

Click **Associate IAM roles**. Show pop-up IAM roles. Choose **redshiftsqlworkbench** that already created first and click **Associate IAM roles** again. The **redshiftsqlworkbench** IAM roles is default.

![](https://cdn-images-1.medium.com/max/2000/1*2nMMUtHPbPfwyq7N6w08xA.jpeg)

![](https://cdn-images-1.medium.com/max/2000/1*DiRVJpBDSGfXI8oQAembZQ.jpeg)

![](https://cdn-images-1.medium.com/max/2000/1*rVvFE0HYs1aQlpNUj8sYEw.jpeg)

![DISABLED USE DEFAULTS](https://cdn-images-1.medium.com/max/2000/1*zh8YYDfhtwxNdmAV2VNk1Q.jpeg)

After disabled use defaults, choose VPC that connected to Redshift subnet group.

![](https://cdn-images-1.medium.com/max/2000/1*HW_qYbIjQZ-Xp8RUhzIEEg.jpeg)

Choose VPC security groups for Redshift. To create VPC security groups, you can see [this link](https://dev.to/budionosan/networking-on-aws-amazon-virtual-private-cloud-vpc-4phd). Choose Redshift cluster subnet group that already create first.

![](https://cdn-images-1.medium.com/max/2000/1*2vZmvgdM5iry3d1S2v8T0w.jpeg)

Fill in the database name and port.

![](https://cdn-images-1.medium.com/max/2000/1*mvLlZbClGZC4kt5BMVTfiQ.jpeg)

If need automated snapshot for backup, can fill 1–35 days. But if don’t need this, can fill 0 days.

![](https://cdn-images-1.medium.com/max/2000/1*QrboasgcK7D1Nuz9dT6USA.jpeg)

Disabled for cross-region snapshot and cluster relocation. Click create cluster to next step.

![](https://cdn-images-1.medium.com/max/2000/1*w40dGMKMgpZ_CsqWswpL5w.jpeg)

Waiting Redshift cluster until the Redshift cluster is available. After the Redshift cluster is available, click the Redshift cluster name.

![](https://cdn-images-1.medium.com/max/2000/1*xhkd6mKoF3FXVKWVIQ5toA.jpeg)

![](https://cdn-images-1.medium.com/max/2508/1*p5fuvQ4juq7Qs5-ABZBYOQ.jpeg)

Click query in query editor version 1 or version 2. For this tutorial, choose version 1.

![](https://cdn-images-1.medium.com/max/2568/1*g7W7Sf1b7BRgZx4H3REJKA.jpeg)

When want query, must connect to the database. Connecting to the database has 2 ways — temporary credentials and AWS Secret Manager. For this tutorial, use AWS Secret Manager.

[Temporary credentials](https://docs.aws.amazon.com/redshift/latest/mgmt/generating-user-credentials.html) based on permissions granted through an [AWS Identity and Access Management (IAM)](https://aws.amazon.com/iam/) permissions policy to manage the access that your users have to your Amazon Redshift database.

[AWS Secret Manager](https://aws.amazon.com/secrets-manager/) is an AWS service that stores encrypted secrets such as database credentials (on Amazon RDS, Amazon Redshift, and many more) and API keys.

![](https://cdn-images-1.medium.com/max/2350/1*5TQW73roobd5ktHimYgulQ.jpeg)

When using AWS Secret Manager, create a secret name. Fill in the database name, database user, and password that was already created when creating Redshift cluster. Then choose Redshift cluster to connect. Click **Connect**.

![](https://cdn-images-1.medium.com/max/2000/1*_an_Nvxi7yERjXjHx1IgoQ.jpeg)

After connecting to the database, now can query with one table — sales from [ETL jobs by AWS Glue](https://dev.to/budionosan/analytics-on-aws-aws-glue-3341).

![](https://cdn-images-1.medium.com/max/2376/1*xZgQJAL45FsdeCMwBFuHqg.jpeg)

Query sales table. **SELECT * FROM sales;** need 35 seconds to query this table, show 9994 rows.

![](https://cdn-images-1.medium.com/max/2000/1*sM_eNDcHsbwNZIKEthbNww.jpeg)

![](https://cdn-images-1.medium.com/max/2000/1*v4eU6tboR7B8NZHOOBrGdw.jpeg)

Query sales table with need specific column. Use category, segment and state columns. **WHERE category = ‘Office Supplies’ AND segment = ‘Home Office’ AND state = ‘Texas’;** need 10 seconds for query this table, show 92 rows because this query show office supplies, home office and Texas only.

![](https://cdn-images-1.medium.com/max/2000/1*HmeSzLZ8hqnTrCqv96THEw.jpeg)

![](https://cdn-images-1.medium.com/max/2000/1*4bOq4ClNI7sR5MeNRQM50A.jpeg)

If want delete sales table, write **DROP TABLE dev.public.sales;** click Run and wait until this table is deleted.

![](https://cdn-images-1.medium.com/max/2000/1*N7upF87fso17flbI59eSlg.jpeg)

I want to copy the CSV file from Amazon S3 to Amazon Redshift with COPY command. Create a table with table name — sales and create schema and type data. COPY sales table from Amazon S3 CSV path, need IAM role for Redshift, delimiter comma, format file CSV, IGNOREHEADER to skip file headers in a CSV file and region when Redshift cluster is created. Then click Run and wait until finished. Need 69 seconds to process this query.

![](https://cdn-images-1.medium.com/max/2000/1*OZygMs3r5A4hBKrnjTvbhg.jpeg)

After processing previous query, try check with **SELECT * FROM sales;** need 12 seconds and show 8399 rows with 7 columns.

![](https://cdn-images-1.medium.com/max/2000/1*jQdGe0N0nKBTqJHoKRABOg.jpeg)

![](https://cdn-images-1.medium.com/max/2000/1*WRFV0ARuXhywF9L4qmqNug.jpeg)

Thank you very much for reading this article/tutorial :)