{"id":4195,"date":"2023-11-04T23:14:08","date_gmt":"2023-11-04T23:14:08","guid":{"rendered":"http:\/\/localhost:10003\/creating-a-data-pipeline-to-process-data-using-aws-glue\/"},"modified":"2023-11-05T05:47:56","modified_gmt":"2023-11-05T05:47:56","slug":"creating-a-data-pipeline-to-process-data-using-aws-glue","status":"publish","type":"post","link":"http:\/\/localhost:10003\/creating-a-data-pipeline-to-process-data-using-aws-glue\/","title":{"rendered":"Creating a Data Pipeline to process data using AWS Glue"},"content":{"rendered":"

Data analytics is the new trend among businesses looking to gain insights and competitive advantage. Nevertheless, to extract insights from data, it must first be cleaned, transformed, and analyzed in a usable format. Raw data, often scattered across multiple systems, requires a system in place to collect, process and store it. This system is called a data pipeline. AWS Glue is an integration service that makes it easy to move data among Amazon Web Services data storage and processing services. It is serverless, scalable, and fully-managed, allowing data to be processed without having to manage any infrastructure.<\/p>\n

In this tutorial, we will learn how to create a data pipeline using AWS Glue to transform data stored in an Amazon S3 bucket. We will cover the following topics:<\/p>\n

    \n
  1. Setting up the AWS Glue environment<\/li>\n
  2. Creating an Amazon S3 bucket and folder structure<\/li>\n
  3. Defining the Glue Data Catalog<\/li>\n
  4. Creating a crawler to populate the Data Catalog<\/li>\n
  5. Creating a Glue job to transform the data<\/li>\n
  6. Running a job and verifying the output<\/li>\n<\/ol>\n

    Setting up the AWS Glue environment<\/h2>\n

    To use AWS Glue, you must first sign up for an AWS account. Once you have signed up, navigate to the AWS Management Console and select AWS Glue from the list of services. This will take you to the AWS Glue console, where you can create and manage your data pipelines.<\/p>\n

    Creating an Amazon S3 bucket and folder structure<\/h2>\n

    To store the data we want to process, we need an Amazon S3 bucket where we can create a folder structure to organize our data. To create a new S3 bucket, navigate to the S3 console and click the “Create Bucket” button. Give your bucket a unique name and choose your desired region. After creating the bucket, create two new folders within it, “input” and “output”. The input folder will contain the raw data we want to process, and the output folder will contain the transformed data.<\/p>\n

    Defining the Glue Data Catalog<\/h2>\n

    The Glue Data Catalog is a central metadata repository that stores metadata information about data sources, schemas, and associated metadata. The data in the Data Catalog serves as a foundation for the Glue ETL jobs. To define the Glue Data Catalog, we need to first create a database. To create a new database, click on the “Databases” tab in the AWS Glue console and then click the “Add database” button. Give your database a name and click “Create.” Once the database is created, you should see it listed in the Databases tab of the AWS Glue console.<\/p>\n

    Creating a crawler to populate the Data Catalog<\/h2>\n

    A crawler is used to populate the Glue Data Catalog with metadata information about the data being processed. To create a new crawler, click on the “Crawlers” tab in the AWS Glue console and then click “Add crawler.” Give your crawler a name and select the data store you want to crawl. In our case, we will select the input folder in our S3 bucket.<\/p>\n

    Next, we need to configure the crawler to populate the Glue Data Catalog with the metadata about the data. To do this, click on the “Configure crawler” button and select “Add database” to associate the crawler with the database we created earlier. Once the crawler is associated with the database, the “Configure the crawler’s output” section should be populated. Here, we choose the output path for the crawler and decide if the crawler should crawl tables matching a specific pattern.<\/p>\n

    The last step in configuring the crawler is to set up a schedule for it. The default setting is to run one time, but we will change this to run hourly. Finally, start the crawler by clicking on the “Run it now” button. The crawler will then begin the process of analyzing the data in our S3 bucket and populating the Glue Data Catalog with metadata.<\/p>\n

    Creating a Glue job to transform the data<\/h2>\n

    Once the crawler has finished running and populated the Glue Data Catalog, we can create a Glue job to transform the data. To create a new job, navigate to the “Jobs” tab in the AWS Glue console and click “Add job.” Give your job a unique name, select the IAM role you want to use for the job, and then click “Next.”<\/p>\n

    In the next step, we will select the “data source.” Here, we specify where the data we want to transform is located, in our case, the input folder in the S3 bucket. Select the data source type as “Data Catalog” and then click on the “Browse” button to select the table created by the crawler. After selecting the table, click “Next.”<\/p>\n

    In the “Map the source columns to target columns” step, we define the transformation logic using code written in Python or Scala. AWS Glue provides a range of transformations that can be applied to data, and these transformations can be chained together to perform more complex data processing. We can write the transformation code either in the script editor on the console or using external tools and uploading the code as a package.<\/p>\n

    In this example, we will use the script editor provided on the console. The following Python code can be used to transform the raw data:<\/p>\n

    import sys\nfrom awsglue.transforms import *\nfrom awsglue.utils import getResolvedOptions\nfrom awsglue.context import GlueContext\nfrom pyspark.context import SparkContext\nfrom pyspark.sql.functions import *\n\n## @params: [JOB_NAME]\nargs = getResolvedOptions(sys.argv, ['JOB_NAME'])\n\nsc = SparkContext()\nglueContext = GlueContext(sc)\nspark = glueContext.spark_session\n\n## @type: DataSource\n## @args: [database = \"mydatabase\", table_name = \"mytable\"]\n## @return: myinputdata\n## @inputs: []\nmyinputdata = glueContext.create_dynamic_frame.from_catalog(database=\"mydatabase\", table_name=\"mytable\")\n\n## Read data from the inputdata\nmydata = myinputdata.toDF()\n\n## Transform the data\nmydata = mydata.select('timestamp', 'value').groupBy('timestamp').agg(avg('value').alias('average'))\n\n## Output the transformed data\nmyoutputdata = DynamicFrame.fromDF(mydata, glueContext, \"transformed_output\")\nglueContext.write_dynamic_frame.from_options(myoutputdata, connection_type=\"s3\", connection_options={\"path\": \"s3:\/\/mybucket\/output\"}, format=\"parquet\")\n<\/code><\/pre>\n

    This transformation logic reads the raw data and aggregates it by timestamp and calculates the average. Then, it saves the transformed data in the output folder in a parquet format.<\/p>\n

    Running a job and verifying the output<\/h3>\n

    Once we have finished defining the transformation logic, we can run the job. To run the job, navigate to the Jobs tab in the AWS Glue console, select the job you want to run, and then click the “Run” button. Once the job is complete, we can verify the output by navigating to the S3 console, selecting the output folder, and viewing the transformed data files.<\/p>\n

    Conclusion<\/h2>\n

    In this tutorial, we learned how to create a data pipeline using AWS Glue to transform data stored in an Amazon S3 bucket. AWS Glue simplifies the process of building data processing pipelines by providing a serverless, fully-managed, scalable platform to process and transform data. By using these steps, you can transform any raw data and load it in a structured way for further analysis.<\/p>\n","protected":false},"excerpt":{"rendered":"

    Data analytics is the new trend among businesses looking to gain insights and competitive advantage. Nevertheless, to extract insights from data, it must first be cleaned, transformed, and analyzed in a usable format. Raw data, often scattered across multiple systems, requires a system in place to collect, process and store Continue Reading<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[1],"tags":[317,202,387,30,468,95,1637],"yoast_head":"\nCreating a Data Pipeline to process data using AWS Glue - Pantherax Blogs<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/localhost:10003\/creating-a-data-pipeline-to-process-data-using-aws-glue\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Creating a Data Pipeline to process data using AWS Glue\" \/>\n<meta property=\"og:description\" content=\"Data analytics is the new trend among businesses looking to gain insights and competitive advantage. Nevertheless, to extract insights from data, it must first be cleaned, transformed, and analyzed in a usable format. Raw data, often scattered across multiple systems, requires a system in place to collect, process and store Continue Reading\" \/>\n<meta property=\"og:url\" content=\"http:\/\/localhost:10003\/creating-a-data-pipeline-to-process-data-using-aws-glue\/\" \/>\n<meta property=\"og:site_name\" content=\"Pantherax Blogs\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-04T23:14:08+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-11-05T05:47:56+00:00\" \/>\n<meta name=\"author\" content=\"Panther\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Panther\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\n\t \"@context\": \"https:\/\/schema.org\",\n\t \"@graph\": [\n\t {\n\t \"@type\": \"Article\",\n\t \"@id\": \"http:\/\/localhost:10003\/creating-a-data-pipeline-to-process-data-using-aws-glue\/#article\",\n\t \"isPartOf\": {\n\t \"@id\": \"http:\/\/localhost:10003\/creating-a-data-pipeline-to-process-data-using-aws-glue\/\"\n\t },\n\t \"author\": {\n\t \"name\": \"Panther\",\n\t \"@id\": \"http:\/\/localhost:10003\/#\/schema\/person\/b63d816f4964b163e53cbbcffaa0f3d7\"\n\t },\n\t \"headline\": \"Creating a Data Pipeline to process data using AWS Glue\",\n\t \"datePublished\": \"2023-11-04T23:14:08+00:00\",\n\t \"dateModified\": \"2023-11-05T05:47:56+00:00\",\n\t \"mainEntityOfPage\": {\n\t \"@id\": \"http:\/\/localhost:10003\/creating-a-data-pipeline-to-process-data-using-aws-glue\/\"\n\t },\n\t \"wordCount\": 1051,\n\t \"publisher\": {\n\t \"@id\": \"http:\/\/localhost:10003\/#organization\"\n\t },\n\t \"keywords\": [\n\t \"\\\"Amazon Web Services\\\"\",\n\t \"\\\"AWS\\\"\",\n\t \"\\\"big data\\\"\",\n\t \"\\\"cloud computing\\\"\",\n\t \"\\\"data pipeline\\\"\",\n\t \"\\\"data processing\\\"\",\n\t \"[\\\"AWS Glue\\\"\"\n\t ],\n\t \"inLanguage\": \"en-US\"\n\t },\n\t {\n\t \"@type\": \"WebPage\",\n\t \"@id\": \"http:\/\/localhost:10003\/creating-a-data-pipeline-to-process-data-using-aws-glue\/\",\n\t \"url\": \"http:\/\/localhost:10003\/creating-a-data-pipeline-to-process-data-using-aws-glue\/\",\n\t \"name\": \"Creating a Data Pipeline to process data using AWS Glue - Pantherax Blogs\",\n\t \"isPartOf\": {\n\t \"@id\": \"http:\/\/localhost:10003\/#website\"\n\t },\n\t \"datePublished\": \"2023-11-04T23:14:08+00:00\",\n\t \"dateModified\": \"2023-11-05T05:47:56+00:00\",\n\t \"breadcrumb\": {\n\t \"@id\": \"http:\/\/localhost:10003\/creating-a-data-pipeline-to-process-data-using-aws-glue\/#breadcrumb\"\n\t },\n\t \"inLanguage\": \"en-US\",\n\t \"potentialAction\": [\n\t {\n\t \"@type\": \"ReadAction\",\n\t \"target\": [\n\t \"http:\/\/localhost:10003\/creating-a-data-pipeline-to-process-data-using-aws-glue\/\"\n\t ]\n\t }\n\t ]\n\t },\n\t {\n\t \"@type\": \"BreadcrumbList\",\n\t \"@id\": \"http:\/\/localhost:10003\/creating-a-data-pipeline-to-process-data-using-aws-glue\/#breadcrumb\",\n\t \"itemListElement\": [\n\t {\n\t \"@type\": \"ListItem\",\n\t \"position\": 1,\n\t \"name\": \"Home\",\n\t \"item\": \"http:\/\/localhost:10003\/\"\n\t },\n\t {\n\t \"@type\": \"ListItem\",\n\t \"position\": 2,\n\t \"name\": \"Creating a Data Pipeline to process data using AWS Glue\"\n\t }\n\t ]\n\t },\n\t {\n\t \"@type\": \"WebSite\",\n\t \"@id\": \"http:\/\/localhost:10003\/#website\",\n\t \"url\": \"http:\/\/localhost:10003\/\",\n\t \"name\": \"Pantherax Blogs\",\n\t \"description\": \"\",\n\t \"publisher\": {\n\t \"@id\": \"http:\/\/localhost:10003\/#organization\"\n\t },\n\t \"potentialAction\": [\n\t {\n\t \"@type\": \"SearchAction\",\n\t \"target\": {\n\t \"@type\": \"EntryPoint\",\n\t \"urlTemplate\": \"http:\/\/localhost:10003\/?s={search_term_string}\"\n\t },\n\t \"query-input\": \"required name=search_term_string\"\n\t }\n\t ],\n\t \"inLanguage\": \"en-US\"\n\t },\n\t {\n\t \"@type\": \"Organization\",\n\t \"@id\": \"http:\/\/localhost:10003\/#organization\",\n\t \"name\": \"Pantherax Blogs\",\n\t \"url\": \"http:\/\/localhost:10003\/\",\n\t \"logo\": {\n\t \"@type\": \"ImageObject\",\n\t \"inLanguage\": \"en-US\",\n\t \"@id\": \"http:\/\/localhost:10003\/#\/schema\/logo\/image\/\",\n\t \"url\": \"http:\/\/localhost:10003\/wp-content\/uploads\/2023\/11\/cropped-9e7721cb-2d62-4f72-ab7f-7d1d8db89226.jpeg\",\n\t \"contentUrl\": \"http:\/\/localhost:10003\/wp-content\/uploads\/2023\/11\/cropped-9e7721cb-2d62-4f72-ab7f-7d1d8db89226.jpeg\",\n\t \"width\": 1024,\n\t \"height\": 1024,\n\t \"caption\": \"Pantherax Blogs\"\n\t },\n\t \"image\": {\n\t \"@id\": \"http:\/\/localhost:10003\/#\/schema\/logo\/image\/\"\n\t }\n\t },\n\t {\n\t \"@type\": \"Person\",\n\t \"@id\": \"http:\/\/localhost:10003\/#\/schema\/person\/b63d816f4964b163e53cbbcffaa0f3d7\",\n\t \"name\": \"Panther\",\n\t \"image\": {\n\t \"@type\": \"ImageObject\",\n\t \"inLanguage\": \"en-US\",\n\t \"@id\": \"http:\/\/localhost:10003\/#\/schema\/person\/image\/\",\n\t \"url\": \"http:\/\/2.gravatar.com\/avatar\/b8c0eda5a49f8f31ec32d0a0f9d6f838?s=96&d=mm&r=g\",\n\t \"contentUrl\": \"http:\/\/2.gravatar.com\/avatar\/b8c0eda5a49f8f31ec32d0a0f9d6f838?s=96&d=mm&r=g\",\n\t \"caption\": \"Panther\"\n\t },\n\t \"sameAs\": [\n\t \"http:\/\/localhost:10003\"\n\t ],\n\t \"url\": \"http:\/\/localhost:10003\/author\/pepethefrog\/\"\n\t }\n\t ]\n\t}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Creating a Data Pipeline to process data using AWS Glue - Pantherax Blogs","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/localhost:10003\/creating-a-data-pipeline-to-process-data-using-aws-glue\/","og_locale":"en_US","og_type":"article","og_title":"Creating a Data Pipeline to process data using AWS Glue","og_description":"Data analytics is the new trend among businesses looking to gain insights and competitive advantage. Nevertheless, to extract insights from data, it must first be cleaned, transformed, and analyzed in a usable format. Raw data, often scattered across multiple systems, requires a system in place to collect, process and store Continue Reading","og_url":"http:\/\/localhost:10003\/creating-a-data-pipeline-to-process-data-using-aws-glue\/","og_site_name":"Pantherax Blogs","article_published_time":"2023-11-04T23:14:08+00:00","article_modified_time":"2023-11-05T05:47:56+00:00","author":"Panther","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Panther","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/localhost:10003\/creating-a-data-pipeline-to-process-data-using-aws-glue\/#article","isPartOf":{"@id":"http:\/\/localhost:10003\/creating-a-data-pipeline-to-process-data-using-aws-glue\/"},"author":{"name":"Panther","@id":"http:\/\/localhost:10003\/#\/schema\/person\/b63d816f4964b163e53cbbcffaa0f3d7"},"headline":"Creating a Data Pipeline to process data using AWS Glue","datePublished":"2023-11-04T23:14:08+00:00","dateModified":"2023-11-05T05:47:56+00:00","mainEntityOfPage":{"@id":"http:\/\/localhost:10003\/creating-a-data-pipeline-to-process-data-using-aws-glue\/"},"wordCount":1051,"publisher":{"@id":"http:\/\/localhost:10003\/#organization"},"keywords":["\"Amazon Web Services\"","\"AWS\"","\"big data\"","\"cloud computing\"","\"data pipeline\"","\"data processing\"","[\"AWS Glue\""],"inLanguage":"en-US"},{"@type":"WebPage","@id":"http:\/\/localhost:10003\/creating-a-data-pipeline-to-process-data-using-aws-glue\/","url":"http:\/\/localhost:10003\/creating-a-data-pipeline-to-process-data-using-aws-glue\/","name":"Creating a Data Pipeline to process data using AWS Glue - Pantherax Blogs","isPartOf":{"@id":"http:\/\/localhost:10003\/#website"},"datePublished":"2023-11-04T23:14:08+00:00","dateModified":"2023-11-05T05:47:56+00:00","breadcrumb":{"@id":"http:\/\/localhost:10003\/creating-a-data-pipeline-to-process-data-using-aws-glue\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/localhost:10003\/creating-a-data-pipeline-to-process-data-using-aws-glue\/"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/localhost:10003\/creating-a-data-pipeline-to-process-data-using-aws-glue\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/localhost:10003\/"},{"@type":"ListItem","position":2,"name":"Creating a Data Pipeline to process data using AWS Glue"}]},{"@type":"WebSite","@id":"http:\/\/localhost:10003\/#website","url":"http:\/\/localhost:10003\/","name":"Pantherax Blogs","description":"","publisher":{"@id":"http:\/\/localhost:10003\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/localhost:10003\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/localhost:10003\/#organization","name":"Pantherax Blogs","url":"http:\/\/localhost:10003\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/localhost:10003\/#\/schema\/logo\/image\/","url":"http:\/\/localhost:10003\/wp-content\/uploads\/2023\/11\/cropped-9e7721cb-2d62-4f72-ab7f-7d1d8db89226.jpeg","contentUrl":"http:\/\/localhost:10003\/wp-content\/uploads\/2023\/11\/cropped-9e7721cb-2d62-4f72-ab7f-7d1d8db89226.jpeg","width":1024,"height":1024,"caption":"Pantherax Blogs"},"image":{"@id":"http:\/\/localhost:10003\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"http:\/\/localhost:10003\/#\/schema\/person\/b63d816f4964b163e53cbbcffaa0f3d7","name":"Panther","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/localhost:10003\/#\/schema\/person\/image\/","url":"http:\/\/2.gravatar.com\/avatar\/b8c0eda5a49f8f31ec32d0a0f9d6f838?s=96&d=mm&r=g","contentUrl":"http:\/\/2.gravatar.com\/avatar\/b8c0eda5a49f8f31ec32d0a0f9d6f838?s=96&d=mm&r=g","caption":"Panther"},"sameAs":["http:\/\/localhost:10003"],"url":"http:\/\/localhost:10003\/author\/pepethefrog\/"}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/localhost:10003\/wp-json\/wp\/v2\/posts\/4195"}],"collection":[{"href":"http:\/\/localhost:10003\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/localhost:10003\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/localhost:10003\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/localhost:10003\/wp-json\/wp\/v2\/comments?post=4195"}],"version-history":[{"count":1,"href":"http:\/\/localhost:10003\/wp-json\/wp\/v2\/posts\/4195\/revisions"}],"predecessor-version":[{"id":4331,"href":"http:\/\/localhost:10003\/wp-json\/wp\/v2\/posts\/4195\/revisions\/4331"}],"wp:attachment":[{"href":"http:\/\/localhost:10003\/wp-json\/wp\/v2\/media?parent=4195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/localhost:10003\/wp-json\/wp\/v2\/categories?post=4195"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/localhost:10003\/wp-json\/wp\/v2\/tags?post=4195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}