Analytics on AWS — AWS Glue
Tags: aws, cloud, analytics, glue
Published: 2023-03-13 06:55:29

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

**NOTE**: This article has associated with my article about [Analytics on AWS — Amazon Redshift](https://dev.to/budionosan/analytics-on-aws-amazon-redshift-5175).

Hello everyone, I want to share my experience when I use **AWS Glue**. [AWS Glue](https://aws.amazon.com/glue/) is AWS services serverless data integration from many sources and creating **ETL (extract, transform and load)** pipelines. I use AWS Glue features for:

 1. **AWS Glue Data Catalog** — for creating databases and tables, crawlers, and classifiers.

 2. **AWS Glue Studio** — for ETL (extract, transform, and load) jobs with drag-and-drop and coding.

 3. **AWS Glue Databrew** — for creating connections when connecting from AWS Glue Data Catalog to Amazon Redshift.

Before using AWS Glue, I have [one CSV file](https://github.com/budionosan/learnaws/blob/main/AWS%20Glue/mergeclean.csv) and one Redshift cluster that has already been created for the ETL jobs process. Go to the Analytics section and click AWS Glue. You can see **Data Catalog**, and click Classifiers.

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

Click **Add classifier**. The classifiers worked when triggered by crawlers.

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

Fill in the classifier name. Because I have one CSV file, I choose CSV format for this classifier. For column delimiter, choose comma. Click **Create** if already filled.

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

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

The databases must have one or more tables. Then click Databases and click **Add database**. Fill in the database name and click **Create database**.

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

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

The crawlers worked to create a table, and connect data sources like Amazon S3, JDBC, Amazon DynamoDB, and many more. Click **Create crawler**.

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

Fill in the crawler name. If do not have a data source, choose No and click add a data source. I have one CSV file in Amazon S3. This CSV file is used for this article/tutorial.

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

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

![Amazon S3](https://cdn-images-1.medium.com/max/2328/1*aAj394VTMfS0BZX1kKA2Uw.jpeg)

Choose S3 for the data source. Location of S3 data in this account and use S3 path when I store the CSV file. Choose to crawl all sub-folders. Then click **Add an S3 data source**.

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

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

When already add data source, show the data source with Amazon S3. Choose classifiers that already created. Click **Next**.

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

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

For IAM role AWS Glue, click create new IAM role if not have IAM role. After creating IAM role, can choose your IAM role. Click **Next**.

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

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

For the target database, choose the database that has already been created. While crawling the schedule, choose on-demand because I want to crawl my CSV file one time only. Click **Next**. When until review and create steps, click **Create crawler**.

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

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

The crawlers are ready. If want crawl CSV file, click **Run** and can see the crawlers process is running.

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

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

When the crawler process is finished, show **Succeeded** and have one table after when the crawler process is running. Click the crawler name and can see one table from one database and location S3 path also classifiers **CSV**. You can see the schema from this table.

![](https://cdn-images-1.medium.com/max/2366/1*xe-wY23jrRH5Z_d2VcRMAA.jpeg)

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

![](https://cdn-images-1.medium.com/max/2000/1*9qJQ3Bf-LrZYO-erJdJ98A.jpeg)

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

Go to the Analytics section again and click AWS Glue Databrew to create connections.

![AWS Glue Databrew](https://cdn-images-1.medium.com/max/2416/1*N79d80dxR_Jy-uJY8SjjGg.jpeg)

Fill in the connection name. Because want ETL jobs from AWS Glue Data Catalog to Amazon Redshift, use Amazon Redshift for connection type.

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

Choose Redshift cluster that already created, database name, database username and also password. Click **Create connection**.

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

Still on AWS Glue. See **Data Integration and ETL**, click AWS Glue Studio like this screenshot.

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

Create ETL jobs with a visual with a source and target. Source from AWS Glue Data Catalog and target to Amazon Redshift. Click **Create**. You can also create ETL jobs using Spark, Python, or Notebook code.

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

On the data source from AWS Glue Data Catalog, choose the database and table that have already been created to data source properties — Data Catalog.

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

The node properties can edit the name and node type, but don’t want to change. For output, the schema is the same as in the table on AWS Glue Data Catalog.

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

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

Then go to Transform. [Apply Mapping](https://docs.aws.amazon.com/glue/latest/ug/transforms-configure-appplymapping.html) remaps the source data property keys into the desired configured for the target data. Transform in Apply Mapping can choose the drop source key and change the data type.

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

The node properties can edit the name, node type, and node parents. Node parents used before transform such as data source (AWS Glue Data Catalog), but I don’t want change. For output, the schema is same as in the table on AWS Glue Data Catalog.

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

On data target to Amazon Redshift, choose database and table.

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

The node properties can edit name, node type and node parents. Node parents used after transform and target to Amazon Redshift, but do not want change. For output, the schema is same as in the table on AWS Glue Data Catalog.

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

When visual mode is already finished like this. Click **Script** for see ETL jobs code.

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

When in script mode, if click Confirm when you want edit script, cannot back to visual mode.

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

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

Use coding ETL jobs. For the code, I share [my code](https://github.com/budionosan/learnaws/blob/main/AWS%20Glue/gluestudio.py) to my GitHub. Copy my code and paste to script mode.

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

After coding ETL jobs is finished, click **Job details**. Fill in the job name and choose IAM role for Glue Studio. Use IAM role when create data catalog on AWS Glue Data Catalog.

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

Choose Spark for ETL jobs type, Glue 3.0, use Python 3 and G 1X for worker type when ETL jobs running.

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

Use 3 workers for ETL jobs running. Job bookmark is enabled for process ETL jobs when running. For number of retry, don’t use retry alias 0.

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

Choose connections from AWS Glue Databrew connections that have already been created. The Databrew connection connected with VPC, subnet, and security groups (also connect to Amazon Redshift).

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

Go to Amazon Redshift, go to Redshift cluster, click query data version 1, and connect to the database with AWS Secret Manager.

When job details are already finished, click **Save** to update the job configuration. Click **Run** for running ETL jobs and click **Run Details** to see more details on how ETL jobs are running.

![Updated ETL job](https://cdn-images-1.medium.com/max/2540/1*Ffiz1hoShOF-0ec3iDFFfA.jpeg)

![Started ETL job](https://cdn-images-1.medium.com/max/2540/1*fqG1aYZ3SoAwB4Dv066U_w.jpeg)

Wait ETL jobs until run status is Succeeded. This ETL jobs need 59 seconds only.

![ETL jobs is successful](https://cdn-images-1.medium.com/max/2506/1*UAyk106AV_LHpRTVgYr3qw.jpeg)

Refresh until table results from ETL jobs is available.

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

Thank you very much :) I want try AWS Glue Databrew. Thank you again. See you again.