Many shoppers are inquisitive about boosting productiveness of their software program improvement lifecycle by utilizing generative AI. Lately, AWS introduced the final availability of Amazon CodeWhisperer, an AI coding companion that makes use of foundational fashions underneath the hood to enhance software program developer productiveness. With Amazon CodeWhisperer, you may rapidly settle for the highest suggestion, view extra options, or proceed writing your personal code. This integration reduces the general time spent in writing knowledge integration and extract, rework, and cargo (ETL) logic. It additionally helps beginner-level programmers write their first traces of code. AWS Glue Studio notebooks means that you can creator knowledge integration jobs with a web-based serverless pocket book interface.
On this submit, we talk about real-world use circumstances for CodeWhisperer powered by AWS Glue Studio notebooks.
Answer overview
For this submit, you utilize the CSV eSports Earnings dataset, obtainable to obtain by way of Kaggle. The information is scraped from eSportsEarnings.com, which gives info on earnings of eSports gamers and groups. The target is to carry out transformations utilizing an AWS Glue Studio pocket book with CodeWhisperer suggestions after which write the info again to Amazon Easy Storage Service (Amazon S3) in Parquet file format in addition to to Amazon Redshift.
Conditions
Our answer has the next stipulations:
- Arrange AWS Glue Studio.
- Configure an AWS Id and Entry Administration (IAM) position to work together with CodeWhisperer. Connect the next coverage to your IAM position that’s connected to the AWS Glue Studio pocket book:
- Obtain the CSV eSports Earnings dataset and add the CSV file
highest_earning_players.csv
to the S3 folder you’ll be utilizing on this use case.
Create an AWS Glue Studio pocket book
Let’s get began. Create a brand new AWS Glue Studio pocket book job by finishing the next steps:
- On the AWS Glue console, select Notebooks underneath ETL jobs within the navigation pane.
- Choose Jupyter Pocket book and select Create.
- For Job title, enter
CodeWhisperer-s3toJDBC
.
A brand new pocket book shall be created with the pattern cells as proven within the following screenshot.
We use the second cell for now, so you may take away all the opposite cells.
- Within the second cell, replace the interactive session configuration by setting the next:
- Employee sort to G.1X
- Variety of staff to three
- AWS Glue model to 4.0
- Furthermore, import the
DynamicFrame
module andcurrent_timestamp
perform as follows:
After you make these modifications, the pocket book ought to be wanting like the next screenshot.
Now, let’s guarantee CodeWhisperer is working as supposed. On the backside proper, you can find the CodeWhisperer possibility beside the Glue PySpark standing, as proven within the following screenshot.
You may select CodeWhisperer to view the choices to make use of Auto-Options.
Develop your code utilizing CodeWhisperer in an AWS Glue Studio pocket book
On this part, we present find out how to develop an AWS Glue pocket book job for Amazon S3 as a knowledge supply and JDBC knowledge sources as a goal. For our use case, we have to guarantee Auto-Options are enabled. Write your advice utilizing CodeWhisperer utilizing the next steps:
- Write a remark in pure language (in English) to learn Parquet recordsdata out of your S3 bucket:
After you enter the previous remark and press Enter, the CodeWhisperer button on the finish of the web page will present that it’s operating to write down the advice. The output of the CodeWhisperer advice will seem within the subsequent line and the code is chosen after you press Tab. You may study extra in Person actions.
After you enter the previous remark, CodeWhisperer will generate a code snippet that’s much like the next:
Word that you should replace the paths to match the S3 bucket you’re utilizing as a substitute of the CodeWhisperer-generated bucket.
From the previous code snippet, CodeWhisperer used Spark DataFrames to learn the CSV recordsdata.
- Now you can strive some rephrasing to get a suggestion with DynamicFrame capabilities:
Now CodeWhisperer will generate a code snippet that’s near the next:
Rephrasing the sentences written now has proved that after some modifications to the feedback we wrote, we acquired the proper advice from CodeWhisperer.
- Subsequent, use CodeWhisperer to print the schema of the previous AWS Glue DynamicFrame by utilizing the next remark:
CodeWhisperer will generate a code snippet that’s near the next:
We get the next output.
Now we use CodeWhisperer to create some transformation capabilities that may manipulate the AWS Glue DynamicFrame learn earlier. We begin by getting into code in a brand new cell.
- First, check if CodeWhisperer can use the proper AWS Glue context capabilities like ResolveChoice:
CodeWhisperer has really useful a code snippet much like the next:
The previous code snippet doesn’t precisely characterize the remark that we entered.
- You may apply sentence paraphrasing and simplifying by offering the next three feedback. Each has totally different ask and we use the withColumn Spark Body methodology, which is utilized in casting columns sorts:
CodeWhisperer will choose up the previous instructions and suggest the next code snippet in sequence:
The next output confirms the PlayerId
column is modified from string to integer.
- Apply the identical course of to the resultant AWS Glue DynamicFrame for the
TotalUSDPrize
column by casting it from string to lengthy utilizing thewithColumn
Spark Body capabilities by getting into the next feedback:
The really useful code snippet is much like the next:
The output schema of the previous code snippet is as follows.
Now we are going to attempt to suggest a code snippet that displays the typical prize for every participant in keeping with their nation code.
- To take action, begin by getting the depend of the participant per every nation:
The really useful code snippet is much like the next:
We get the next output.
- Be part of the principle DataFrame with the nation code depend DataFrame after which add a brand new column calculating the typical highest prize for every participant in keeping with their nation code:
The really useful code snippet is much like the next:
The output of the schema now confirms the each DataFrames the place appropriately joined and the Depend
column is added to the principle DataFrame.
- Get the code advice on the code snippet to calculate the typical
TotalUSDPrize
for every nation code and add it to a brand new column:
The really useful code snippet is much like the next:
The output of the previous code ought to appear to be the next.
- Be part of the
country_code_sum
DataFrame with the principle DataFrame from earlier and get the typical of the prizes per participant per nation:
The really useful code snippet is much like the next:
- The final half within the transformation section is to type the info by the very best common prize per participant per nation:
The really useful code snippet is much like the next:
The primary 5 rows shall be much like the next.
For the final step, we write the DynamicFrame to Amazon S3 and to Amazon Redshift.
- Write the DynamicFrame to Amazon S3 with the next code:
The CodeWhisperer advice is much like the next code snippet:
We have to right the code snippet generated after the advice as a result of it doesn’t comprise partition keys. As we identified, partitionkeys
is empty, so we will have one other code block suggestion to set partitionkey
after which write it to the goal Amazon S3 location. Additionally, in keeping with the most recent updates associated to writing DynamicFrames to Amazon S3 utilizing glueparquet, format = "glueparquet"
is not used. As an alternative, you should use the parquet sort with useGlueParquetWriter
enabled.
After the updates, our code seems much like the next:
An alternative choice right here can be to write down the recordsdata to Amazon Redshift utilizing a JDBC connection.
- First, enter the next command to test whether or not CodeWhisperer will perceive the remark in a single sentence and use the proper capabilities or not:
The output of the remark is much like the next code snippet:
As we will see, CodeWhisperer appropriately interpreted the remark by choosing solely the desired columns to write down to Amazon Redshift.
- Now, use CodeWhisperer to write down the DynamicFrame to Amazon Redshift. We use the Preaction parameter to run a SQL question to pick solely sure columns to be written to Amazon Redshift:
The CodeWhisperer advice is much like the next code snippet:
After checking the previous code snippet, you may observe that there’s a misplaced format
, which you’ll take away. You can too add the iam_role
as an enter in connection_options
. You can too discover that CodeWhisperer has robotically assumed the Redshift URL to have the identical title because the S3 folder that we used. Subsequently, you should change the URL and the S3 temp listing bucket to replicate your personal parameters and take away the password parameter. The ultimate code snippet ought to be much like the next:
The next is the entire code and remark snippets:
Conclusion
On this submit, we demonstrated a real-world use case on how AWS Glue Studio pocket book integration with CodeWhisperer helps you construct knowledge integration jobs quicker. You can begin utilizing the AWS Glue Studio pocket book with CodeWhisperer to speed up constructing your knowledge integration jobs.
To study extra about utilizing AWS Glue Studio notebooks and CodeWhisperer, take a look at the next video.
Concerning the authors
Ishan Gaur works as Sr. Massive Information Cloud Engineer ( ETL ) specialised in AWS Glue. He’s captivated with serving to prospects constructing out scalable distributed ETL workloads and analytics pipelines on AWS.
Omar Elkharbotly is a Glue SME who works as Massive Information Cloud Assist Engineer 2 (DIST). He’s devoted to aiding prospects in resolving points associated to their ETL workloads and creating scalable knowledge processing and analytics pipelines on AWS.