AWS Big Data Blog
Simplify external object access in Amazon Redshift using automatic mounting of the AWS Glue Data Catalog
Amazon Redshift is a petabyte-scale, enterprise-grade cloud data warehouse service delivering the best price-performance. Today, tens of thousands of customers run business-critical workloads on Amazon Redshift to cost-effectively and quickly analyze their data using standard SQL and existing business intelligence (BI) tools.
Amazon Redshift now makes it easier for you to run queries in AWS data lakes by automatically mounting the AWS Glue Data Catalog. You no longer have to create an external schema in Amazon Redshift to use the data lake tables cataloged in the Data Catalog. Now, you can use your AWS Identity and Access Management (IAM) credentials or IAM role to browse the Glue Data Catalog and query data lake tables directly from Amazon Redshift Query Editor v2 or your preferred SQL editors.
This feature is now available in all AWS commercial and US Gov Cloud Regions where Amazon Redshift RA3, Amazon Redshift Serverless, and AWS Glue are available. To learn more about auto-mounting of the Data Catalog in Amazon Redshift, refer to Querying the AWS Glue Data Catalog.
Enabling easy analytics for everyone
Amazon Redshift is helping tens of thousands of customers manage analytics at scale. Amazon Redshift offers a powerful analytics solution that provides access to insights for users of all skill levels. You can take advantage of the following benefits:
- It enables organizations to analyze diverse data sources, including structured, semi-structured, and unstructured data, facilitating comprehensive data exploration
- With its high-performance processing capabilities, Amazon Redshift handles large and complex datasets, ensuring fast query response times and supporting real-time analytics
- Amazon Redshift provides features like Multi-AZ (preview) and cross-Region snapshot copy for high availability and disaster recovery, and provides authentication and authorization mechanisms to make it reliable and secure
- With features like Amazon Redshift ML, it democratizes ML capabilities across a variety of user personas
- The flexibility to utilize different table formats such as Apache Hudi, Delta Lake, and Apache Iceberg (preview) optimizes query performance and storage efficiency
- Integration with advanced analytical tools empowers you to apply sophisticated techniques and build predictive models
- Scalability and elasticity allow for seamless expansion as data and workloads grow
Overall, Amazon Redshift empowers organizations to uncover valuable insights, enhance decision-making, and gain a competitive edge in today’s data-driven landscape.
The new automatic mounting of the AWS Glue Data Catalog feature enables you to directly query AWS Glue objects in Amazon Redshift without the need to create an external schema for each AWS Glue database you want to query. With automatic mounting the Data Catalog, Amazon Redshift automatically mounts the cluster account’s default Data Catalog during boot or user opt-in as an external database, named awsdatacatalog
.
Relevant use cases for automatic mounting of the AWS Glue Data Catalog feature
You can use tools like Amazon EMR to create new data lake schemas in various formats, such as Apache Hudi, Delta Lake, and Apache Iceberg (preview). However, when analysts want to run queries against these schemas, it requires administrators to create external schemas for each AWS Glue database in Amazon Redshift. You can now simplify this integration using automatic mounting of the AWS Glue Data Catalog.
The following diagram illustrates this architecture.
Solution overview
You can now use SQL clients like Amazon Redshift Query Editor v2 to browse and query awsdatacatalog
. In Query Editor V2, to connect to the awsdatacatalog
database, choose the following:
- Must use authentication method Temporary credentials using your IAM identity with the Redshift provisioned cluster
- Must use the authentication method federated user to connect with a Redshift Serverless workgroup.
Complete the following high-level steps to integrate the automatic mounting of the Data Catalog using Query Editor V2 and a third-party SQL client:
- Provision resources with AWS CloudFormation to populate Data Catalog objects.
- Connect Redshift Serverless and query the Data Catalog as a federated user using Query Editor V2.
- Connect with Redshift provisioned cluster and query the Data Catalog using Query Editor V2.
- Configure permissions on catalog resources using AWS Lake Formation.
- Federate with Redshift Serverless and query the Data Catalog using Query Editor V2 and a third-party SQL client.
- Discover the auto-mounted objects.
- Connect with Redshift provisioned cluster and query the Data Catalog as a federated user using a third-party client.
- Connect with Amazon Redshift and query the Data Catalog as an IAM user using third-party clients.
The following diagram illustrates the solution workflow.
Prerequisites
You should have the following prerequisites:
- An AWS account. If you don’t have one, you can sign up for one.
- A Redshift cluster. For setup instructions, see Create a sample Amazon Redshift cluster.
- Alternatively, you could use a Redshift Serverless endpoint. For setup instructions, see Getting started with Amazon Redshift Serverless.
- The latest Amazon Redshift JDBC driver version.
- A SQL client such as SQL workbench/J.
Provision resources with AWS CloudFormation to populate Data Catalog objects
In this post, we use an AWS Glue crawler to create the external table ny_pub
stored in Apache Parquet format in the Amazon Simple Storage Service (Amazon S3) location s3://redshift-demos/data/NY-Pub/
. In this step, we create the solution resources using AWS CloudFormation to create a stack named CrawlS3Source-NYTaxiData
in either us-east-1
(use the yml download or launch stack) or us-west-2
(use the yml download or launch stack). Stack creation performs the following actions:
- Creates the crawler
NYTaxiCrawler
along with the new IAM roleAWSGlueServiceRole-RedshiftAutoMount
- Creates
automountdb
as the AWS Glue database
When the stack is complete, perform the following steps:
- On the AWS Glue console, under Data Catalog in the navigation pane, choose Crawlers.
- Open
NYTaxiCrawler
and choose Run crawler.
After the crawler is complete, you can see a new table called ny_pub
in the Data Catalog under the automountdb
database.
Alternatively, you can follow the manual instructions from the Amazon Redshift labs to create the ny_pub
table.
Connect with Redshift Serverless and query the Data Catalog as a federated user using Query Editor V2
In this section, we use an IAM role with principal tags to enable fine-grained federated authentication to Redshift Serverless to access auto-mounting AWS Glue objects.
Complete the following steps:
- Create an IAM role and add following permissions. For this post, we add full AWS Glue, Amazon Redshift, and Amazon S3 permissions for demo purposes. In an actual production scenario, it’s recommended to apply more granular permissions.
- On the Tags tab, create a tag with Key as
RedshiftDbRoles
and Value asautomount
.
- In Query Editor V2, run the following SQL statement as an admin user to create a database role named
automount
: - Grant usage privileges to the database role:
- Switch the role to
automountrole
by passing the account number and role name.
- In the Query Editor v2, choose your Redshift Serverless endpoint (right-click) and choose Create connection.
- For Authentication, select Federated user.
- For Database, enter the database name you want to connect to.
- Choose Create connection.
You’re now ready to explore and query the automatic mounting of the Data Catalog in Redshift Serverless.
Connect with Redshift provisioned cluster and query the Data Catalog using Query Editor V2
To connect with Redshift provisioned cluster and access the Data Catalog, make sure you have completed the steps in the preceding section. Then complete the following steps:
- Connect to Redshift Query Editor V2 using the database user name and password authentication method. For example, connect to the
dev
database using the admin user and password. - In an editor tab, assuming the user is present in Amazon Redshift, run the following SQL statement to grant an IAM user access to the Data Catalog:
- As an admin user, choose the Settings icon, choose Account settings, and select Authenticate with IAM credentials.
- Choose Save.
- Switch roles to
automountrole
by passing the account number and role name. - Create or edit the connection and use the authentication method Temporary credentials using your IAM identity.
For more information about this authentication method, see Connecting to an Amazon Redshift database.
You are ready to explore and query the automatic mounting of the Data Catalog in Amazon Redshift.
Discover the auto-mounted objects
This section illustrates the SHOW commands for discovery of auto-mounted objects. See the following code:
Configure permissions on catalog resources using AWS Lake Formation
To maintain backward compatibility with AWS Glue, Lake Formation has the following initial security settings:
- The
Super
permission is granted to the groupIAMAllowedPrincipals
on all existing Data Catalog resources - The Use only IAM access control setting is enabled for new Data Catalog resources
These settings effectively cause access to Data Catalog resources and Amazon S3 locations to be controlled solely by IAM policies. Individual Lake Formation permissions are not in effect.
In this step, we will configure permissions on catalog resources using AWS Lake Formation. Before you create the Data Catalog, you need to update the default settings of Lake Formation so that access to Data Catalog resources (databases and tables) is managed by Lake Formation permissions:
- Change the default security settings for new resources. For instructions, see Change the default permission model.
- Change the settings for existing Data Catalog resources. For instructions, see Upgrading AWS Glue data permissions to the AWS Lake Formation model.
For more information, refer to Changing the default settings for your data lake.
Federate with Redshift Serverless and query the Data Catalog using Query Editor V2 and a third-party SQL client
With Redshift Serverless, you can connect to awsdatacatalog
from a third-party client as a federated user from any identity provider (IdP). In this section, we will configure permission on catalog resources for Federated IAM role in AWS Lake Formation. Using AWS Lake Formation with Redshift, currently permission can be applied on IAM user or IAM role level.
To connect as a federated user, we will be using Redshift Serverless. For setup instructions, refer to Single sign-on with Amazon Redshift Serverless with Okta using Amazon Redshift Query Editor v2 and third-party SQL clients.
There are additional changes required on following resources:
- In Amazon Redshift, as an admin user, grant the usage to each federated user who needs access on
awsdatacatalog
:
If the user doesn’t exist in Amazon Redshift, you may need to create the IAM user with the password disabled as shown in the following code and then grant usage on awsdatacatalog
:
- On the Lake Formation console, assign permissions on the AWS Glue database to the IAM role that you created as part of the federated setup.
- Under Principals, select IAM users and roles.
- Choose IAM role
oktarole
. - Apply catalog resource permissions, selecting
automountdb
database and granting appropriate table permissions.
- Update the IAM role used in the federation setup. In addition to the permissions added to the IAM role, you need to add AWS Glue permissions and Amazon S3 permissions to access objects from Amazon S3. For this post, we add full AWS Glue and AWS S3 permissions for demo purposes. In an actual production scenario, it’s recommended to apply more granular permissions.
Now you’re ready to connect to Redshift Serverless using the Query Editor V2 and federated login.
- Use the SSO URL from Okta and log in to your Okta account with your user credentials. For this demo, we log in with user
Ethan
. - In the Query Editor v2, choose your Redshift Serverless instance (right-click) and choose Create connection.
- For Authentication, select Federated user.
- For Database, enter the database name you want to connect to.
- Choose Create connection.
- Run the command
select current_user
to validate that you are logged in as a federated user.
User Ethan
will be able to explore and access awsdatacatalog
data.
To connect Redshift Serverless with a third-party client, make sure you have followed all the previous steps.
For SQLWorkbench setup, refer to the section Configure the SQL client (SQL Workbench/J) in Single sign-on with Amazon Redshift Serverless with Okta using Amazon Redshift Query Editor v2 and third-party SQL clients.
The following screenshot shows that federated user ethan
is able to query the awsdatacatalog
tables using three-part notation:
Connect with Redshift provisioned cluster and query the Data Catalog as a federated user using third-party clients
With Redshift provisioned cluster, you can connect with awsdatacatalog
from a third-party client as a federated user from any IdP.
To connect as a federated user with the Redshift provisioned cluster, you need to follow the steps in the previous section that detailed how to connect with Redshift Serverless and query the Data Catalog as a federated user using Query Editor V2 and a third-party SQL client.
There are additional changes required in IAM policy. Update the IAM policy with the following code to use the GetClusterCredentialsWithIAM
API:
Now you’re ready to connect to Redshift provisioned cluster using a third-party SQL client as a federated user.
For SQLWorkbench setup, refer to the section Configure the SQL client (SQL Workbench/J) in the post Single sign-on with Amazon Redshift Serverless with Okta using Amazon Redshift Query Editor v2 and third-party SQL clients.
Make the following changes:
- Use the latest Redshift JDBC driver because it only supports querying the auto-mounted Data Catalog table for federated users
- For URL, enter
jdbc:redshift:iam://<cluster endpoint>:<port>:<databasename>?groupfederation=true
. For example,jdbc:redshift:iam://redshift-cluster-1.abdef0abc0ab.us-east-2.redshift.amazonaws.com:5439/dev?groupfederation=true
.
In the preceding URL, groupfederation
is a mandatory parameter that allows you to authenticate with the IAM credentials.
The following screenshot shows that federated user ethan
is able to query the awsdatacatalog
tables using three-part notation.
Connect and query the Data Catalog as an IAM user using third-party clients
In this section, we provide instructions to set up a SQL client to query the auto-mounted awsdatacatalog
.
Use three-part notation to reference the awsdatacatalog table in your SELECT statement. The first part is the database name, the second part is the AWS Glue database name, and the third part is the AWS Glue table name:
You can perform various scenarios that read the Data Catalog data and populate Redshift tables.
For this post, we use SQLWorkbench/J as the SQL client to query the Data Catalog. To set up SQL Workbench/J, complete the following steps:
- Create a new connection in SQL Workbench/J and choose Amazon Redshift as the driver.
- Choose Manage drivers and add all the files from the downloaded AWS JDBC driver pack .zip file (remember to unzip the .zip file).
You must use the latest Redshift JDBC driver because it only supports querying the auto-mounted Data Catalog table.
- For URL, enter
jdbc:redshift:iam://<cluster endpoint>:<port>:<databasename>?profile=<profilename>&groupfederation=true
. For example,jdbc:redshift:iam://redshift-cluster-1.abdef0abc0ab.us-east-2.redshift.amazonaws.com:5439/dev?profile=user2&groupfederation=true
.
We are using profile-based credentials as an example. You can use any AWS profile or IAM credential-based authentication as per your requirement. For more information on IAM credentials, refer to Options for providing IAM credentials.
The following screenshot shows that IAM user johndoe
is able to list the awsdatacatalog
tables using the SHOW command.
The following screenshot shows that IAM user johndoe
is able to query the awsdatacatalog
tables using three-part notation:
If you get the following error while using groupfederation=true
, you need to use the latest Redshift driver:
Clean up
Complete the following steps to clean up your resources:
- Delete the IAM role
automountrole
. - Delete the CloudFormation stack
CrawlS3Source-NYTaxiData
to clean up the crawlerNYTaxiCrawler
, the automountdb database from the Data Catalog, and the IAM roleAWSGlueServiceRole-RedshiftAutoMount
.
- Update the default settings of Lake Formation:
- In the navigation pane, under Data catalog, choose Settings.
- Select both access control options choose Save.
- In the navigation pane, under Permissions, choose Administrative roles and tasks.
- In the Database creators section, choose Grant.
- Search for
IAMAllowedPrincipals
and select Create database permission. - Choose Grant.
Considerations
Note the following considerations:
- The Data Catalog auto-mount provides ease of use to analysts or database users. The security setup (setting up the permissions model or data governance) is owned by account and database administrators.
- To achieve fine-grained access control, build a permissions model in AWS Lake Formation.
- If the permissions have to be maintained at the Redshift database level, leave the AWS Lake Formation default settings as is and then run grant/revoke in Amazon Redshift.
- If you are using a third-party SQL editor, and your query tool does not support browsing of multiple databases, you can use the “SHOW“ commands to list your AWS Glue databases and tables. You can also query
awsdatacatalog
objects using three-part notation (SELECT * FROM awsdatacatalog.<aws-glue-db-name>.<aws-glue-table-name>;
) provided you have access to the external objects based on the permission model.
Conclusion
In this post, we introduced the automatic mounting of AWS Glue Data Catalog, which makes it easier for customers to run queries in their data lakes. This feature streamlines data governance and access control, eliminating the need to create an external schema in Amazon Redshift to use the data lake tables cataloged in AWS Glue Data Catalog. We showed how you can manage permission on auto-mounted AWS Glue-based objects using Lake Formation. The permission model can be easily managed and organized by administrators, allowing database users to seamlessly access external objects they have been granted access to.
As we strive for enhanced usability in Amazon Redshift, we prioritize unified data governance and fine-grained access control. This feature minimizes manual effort while ensuring the necessary security measures for your organization are in place.
For more information about automatic mounting of the Data Catalog in Amazon Redshift, refer to Querying the AWS Glue Data Catalog.
About the Authors
Maneesh Sharma is a Senior Database Engineer at AWS with more than a decade of experience designing and implementing large-scale data warehouse and analytics solutions. He collaborates with various Amazon Redshift Partners and customers to drive better integration.
Debu Panda is a Senior Manager, Product Management at AWS. He is an industry leader in analytics, application platform, and database technologies, and has more than 25 years of experience in the IT world.
Rohit Vashishtha is a Senior Analytics Specialist Solutions Architect at AWS based in Dallas, Texas. He has 17 years of experience architecting, building, leading, and maintaining big data platforms. Rohit helps customers modernize their analytic workloads using the breadth of AWS services and ensures that customers get the best price/performance with utmost security and data governance.