Amazon Web Services Posted May 2 Share Posted May 2 In today’s data-driven landscape, the efficiency and accessibility of querying tools play a crucial role in driving businesses forward. Amazon Redshift recently announced integration with Visual Studio Code (), an action that transforms the way data practitioners engage with Amazon Redshift and reshapes your interactions and practices in data management. This innovation not only unlocks new possibilities, but also tackles long-standing challenges in data analytics and query handling. While the Amazon Redshift query editor v2 (QE v2) offers a smooth experience for data analysts and business users, many organizations have data engineers and developers who rely on VS Code as their primary development tool. Traditionally, they had to use QE v2 for their development tasks, which wasn’t the most optimal solution. However, this new feature resolves that issue by enabling data engineers and developers to seamlessly integrate their development work within VS Code, enhancing their workflow efficiency. Visual Studio Code’s integration simplifies access to database objects within Redshift data warehouses, offering an interface you’re already familiar with to run and troubleshoot your code. By integrating Amazon Redshift Provisioned cluster, and Amazon Redshift Serverless with the popular and free VS Code, you can alleviate concerns about costs associated with third-party tools. This integration allows you to reduce or eliminate licensing expenses for query authoring and data visualization, because these functionalities are now available within the free VSCode editor. The support for Amazon Redshift within VS Code marks a significant leap towards a more streamlined, cost-effective, and user-friendly data querying experience. In this post, we explore how to kickstart your journey with Amazon Redshift using the AWS Toolkit for VS Code. Solution overview This post outlines the procedure for creating a secure and direct connection between your local VS Code environment and the Redshift cluster. Emphasizing both security and accessibility, this solution allows you to operate within the familiar VS Code interface while seamlessly engaging with your Redshift database. The following diagram illustrates the VS Code connection to Amazon Redshift deployed in a private VPC. To connect to a data warehouse using VS Code from the Toolkit, you can choose from the following methods: Use a database user name and password Use AWS Secrets Manager Use temporary credentials (this option is only available with Amazon Redshift Provisioned cluster) In the following sections, we show how to establish a connection with a database situated on an established provisioned cluster or a serverless data warehouse from the Toolkit. Prerequisites Before you begin using Amazon Redshift Provisioned Cluster and Amazon Redshift Serverless with the AWS Toolkit for Visual Studio Code, make sure you’ve completed the following requirements: Connect to your AWS account using the Toolkit. Set up a Amazon Redshift or Amazon Redshift serverless data warehouse. Establish a connection to your data warehouse using user credentials To connect using the database user name and password, complete the following steps: Navigate through the Toolkit explorer, expanding the AWS Region housing your data warehouse (for example, US East (N. Virginia)). In the Toolkit, expand the Redshift section and choose your specific data warehouse. In the Select a Connection Type dialog, choose Database user name and password and provide the necessary information requested by the prompts. After the Toolkit establishes the connection to your data warehouse, you will be able to view your available databases, tables, and schemas directly in the Toolkit explorer. Establish a connection to your data warehouse using Secrets Manager To connect using Secrets Manager, complete the following steps: Navigate through the Toolkit explorer, expanding the AWS Region housing your data warehouse. In the Toolkit, expand the Redshift section and choose your specific data warehouse. In the Select a Connection Type dialog, choose Secrets Manager and fill in the information requested at each prompt. After the Toolkit establishes a successful connection to your data warehouse, you’ll gain visibility into your databases, tables, and schemas directly in the Toolkit explorer. Establish a connection to your Amazon Redshift Provisioned cluster using Temporary credentials: To connect using Temporary credentials complete the following steps: Navigate through the Toolkit explorer, expanding the AWS Region housing your data warehouse. In the Toolkit, expand the Redshift section and choose your specific data warehouse. In the Select a Connection Type dialog, choose Temporary Credentials and fill in the information requested at each prompt. Run SQL statements We have successfully established the connection. The next step involves running some SQL. The steps outlined in this section detail the process of generating and running SQL statements within your database using the Toolkit for Visual Studio Code. Navigate to the Toolkit explorer and expand Redshift, then choose the data warehouse that stores the desired database for querying. Choose Create Notebook and specify a file name and location for saving your notebook locally. Choose OK to open the notebook in your VS Code editor. Enter the following SQL statements into the VS Code editor, which will be stored in this notebook: create table promotion ( p_promo_sk integer not null, p_promo_id char(16) not null, p_start_date_sk integer , p_end_date_sk integer , p_item_sk integer , p_cost decimal(15,2) , p_response_target integer , p_promo_name char(50) , p_channel_dmail char(1) , p_channel_email char(1) , p_channel_catalog char(1) , p_channel_tv char(1) , p_channel_radio char(1) , p_channel_press char(1) , p_channel_event char(1) , p_channel_demo char(1) , p_channel_details varchar(100) , p_purpose char(15) , p_discount_active char(1) , primary key (p_promo_sk) ) diststyle all; create table reason ( r_reason_sk integer not null, r_reason_id char(16) not null, r_reason_desc char(100) , primary key (r_reason_sk) ) diststyle all ; create table ship_mode ( sm_ship_mode_sk integer not null, sm_ship_mode_id char(16) not null, sm_type char(30) , sm_code char(10) , sm_carrier char(20) , sm_contract char(20) , primary key (sm_ship_mode_sk) ) diststyle all; copy promotion from 's3://redshift-downloads/TPC-DS/2.13/1TB/promotion/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; copy reason from 's3://redshift-downloads/TPC-DS/2.13/1TB/reason/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; copy ship_mode from 's3://redshift-downloads/TPC-DS/2.13/1TB/ship_mode/' iam_role default gzip delimiter '|' EMPTYASNULL region 'us-east-1'; select * from promotion limit 10; drop table promotion; drop table reason; drop table ship_mode; Choose Run All to run the SQL statements. The output corresponding to your SQL statements will be visible below the entered statements within the editor. Include markdown in a notebook To include markdown in your notebook, complete the following steps: Access your notebook within the VS Code editor and choose Markdown to create a markdown cell. Enter your markdown content within the designated cell. Use the editing tools in the upper-right corner of the markdown cell to modify the markdown content as needed. Congratulations, you have learned the art of using the VS Code editor to effectively interface with your Redshift environment. Clean up To remove the connection, complete the following steps: In the Toolkit explorer, expand Redshift, and choose the data warehouse containing your database. Choose the database (right-click) and choose Delete Connection. Conclusion In this post, we explored the process of using VS Code to establish a connection with Amazon Redshift, streamlining access to database objects within Redshift data warehouses. You can learn about Amazon Redshift from Getting started with Amazon Redshift guide. Know more about write and run SQL queries directly in VS Code with the new AWS Toolkit for VS Code integration. About the Author Navnit Shukla, an AWS Specialist Solution Architect specializing in Analytics, is passionate about helping clients uncover valuable insights from their data. Leveraging his expertise, he develops inventive solutions that empower businesses to make informed, data-driven decisions. Notably, Navnit Shukla is the accomplished author of the book “Data Wrangling on AWS,” showcasing his expertise in the field.View the full article Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.