Amazon QuickSight is a fast, cloud-powered, business intelligence service that makes it easy to deliver insights and integrates seamlessly with your data lake built on Amazon Simple Storage Service (Amazon S3). QuickSight users in your organization often need access to only a subset of columns for compliance and security reasons. Without having a proper solution to enforce column-level security, you have to develop additional solutions, such as views, data masking, or encryption, to enforce security.
QuickSight accounts can now take advantage of AWS Lake Formation column-level authorization to enforce granular-level access control for their users.
Overview of solution
In this solution, you build an end-to-end data pipeline using Lake Formation to ingest data from an Amazon Aurora MySQL database to an Amazon S3 data lake and use Lake Formation to enforce column-level access control for QuickSight users.
The following diagram illustrates the architecture of this solution.
The detailed steps in this solution include building a data lake using Lake Formation, which uses an Aurora MySQL database as the source and Amazon S3 as the target data lake storage. You create a workflow in Lake Formation that imports a single table from the source database to the data lake. You then use Lake Formation security features to enforce column-level security for QuickSight service on the imported table. Finally, you use QuickSight to connect to this data lake and visualize only the columns for which Lake Formation has given access to QuickSight user.
To implement the solution, you complete the following steps:
- Creating a source database
- Importing a single table from the source database
- Creating a connection to the data source
- Creating and registering your S3 bucket
- Creating a database in the Data Catalog and granting permissions
- Creating and running the workflow
- Granting Data Catalog permissions
- Enforcing column-level security in Lake Formation
- Creating visualizations in QuickSight
For this walkthrough, you should have the following prerequisites:
Creating a source database
In this step, create an Aurora MySQL database cluster and use the DDLs in the following GitHub repo to create an HR schema with associated tables and sample data.
You should then see the schema you created using the MySQL monitor or your preferred SQL client. For this post, I used SQL Workbench. See the following screenshot.
Record the Aurora database JDBC endpoint information; you need it in subsequent steps.
Importing a single table from the source database
Before you complete the following steps, make sure you have set up Lake Formation and met the JDBC prerequisites.
The Lake Formation setup creates a
datalake_user IAM user. You need to add the same user as a QuickSight user. For instructions, see Managing User Access Inside Amazon QuickSight. For Role, choose AUTHOR.
Creating a connection to the data source
After you complete the Lake Formation prerequisites, which include creating IAM users
datalake_user, create a connection in your Aurora database. For instructions, see Create a Connection in AWS Glue. Provide the following information:
- Connection name –
- Connection type – JDBC
- Database connection parameters – JDBC URL, user name, password, VPC, subnet, and security group
Creating and registering your S3 bucket
In this step, you create an S3 bucket named
<yourPrefix>-blog-datalake, which you use as the root location of your data lake. After you create the bucket, you need to register the Amazon S3 path. Lastly, grant data location permissions.
Creating a database in the Data Catalog and granting permissions
Create a database in the Lake Formation Data Catalog named
<yourPrefix>-blog-database, which stores the metadata tables. For instructions, see Create a Database in the Data Catalog.
After you create the database, you grant data permissions to the metadata tables to the
LakeFormationWorkflowRole role, which you use to run the workflows.
Creating and running the workflow
In this step, you copy the
EMPLOYEES table from the source database using a Lake Formation blueprint. Provide the following information:
- Blueprint type – Database snapshot
- Database connection –
- Source data path –
- Target database –
- Target storage location –
- Workflow name –
- IAM role –
- Table prefix –
For instructions, see Use a Blueprint to Create a Workflow.
When the workflow is ready, you can start the workflow and check its status by choosing View graph. When the workflow is complete, you can see the employee table available in your Data Catalog under
<yourPrefix>-blog-database. See the following screenshot.
You can also view the imported data using Athena, which is integrated with Lake Formation. You need to select “View Data” from “Actions” drop down menu for this purpose. See the following screenshot.
Granting Data Catalog permissions
In this step, you provide the Lake Formation Data Catalog access to the IAM user
datalake_user. This is the same user that you added in QuickSight to create the dashboard. For Database permissions, select Create table and Alter for this use case, but you can change the permission level based on your specific requirements. For instructions, see Granting Data Catalog Permissions.
When this step is complete, you see the permissions for your database
Enforcing column-level security in Lake Formation
Now that your table is imported into the data lake, enforce column-level security to the dataset. For this use case, you want to hide the
Phone_Number columns from business intelligence QuickSight users.
- In the Lake Formation Data Catalog, choose Databases.
- From the list of databases, choose
- Choose View tables.
- Select blog_hr_employees.
- From the Actions drop-down menu, choose Grant.
- For Active Directory and Amazon QuickSight users and groups, provide the QuickSight user ARN.
You can find the ARN by entering the code
aws quicksight list-users --aws-account-id <your AWS account id> --namespace default --region us-east-1 in the AWS Command Line Interface (AWS CLI).
- For Database, choose
- For Table, choose
- For Columns, choose Exclude columns.
- For Exclude columns, choose
- For Table permissions, select Select.
You should receive a confirmation on the console that says
Permission granted for: datalake_user to Exclude: <yourPrefix>-blog-database.blog_hr_employees.[salary, phone_number].
You can also verify that appropriate permission is reflected for the QuickSight user on the Lake Formation console by navigating to the Permissions tab and filtering for your database and table.
You can also specify column-level permissions in the AWS CLI with the following code:
Creating visualizations in QuickSight
In this step, you use QuickSight to access the
blog_hr_employees table in your data lake. While accessing this dataset from QuickSight, you can see that QuickSight doesn’t show the
phone_number columns, which you excluded from the source table in the previous step.
- Log in to QuickSight using the
- Choose New analysis.
- Choose New dataset.
- For the data source, choose Athena.
- For your data source name, enter
- For Database, choose
- For Tables, select
- Choose Select.
- Choose Import to SPICE for quicker analysis or Directly query your data.
For this use case, choose Import to SPICE. This provides faster visualization in a production setup, and you can run a scheduled refresh to make sure your dashboards are referring to the current data. For more information, see Scheduled Refresh for SPICE Data Sets on Amazon QuickSight.
When you complete the previous steps, your data is imported to your SPICE machine and you arrive at the QuickSight visualization dashboard. You can see that SPICE has excluded the
phone_number fields from the table. In the following screenshot, we created a pie chart visualization to show how many employees are present in each department.
To avoid incurring future charges, delete the resources you created in this walkthrough, including your S3 bucket, Aurora cluster, and other associated resources.
Restricting access to sensitive data to various users in a data lake is a very common challenge. In this post, we demonstrated how to use Lake Formation to enforce column-level access to QuickSight dashboard users. You can enhance security further with Athena workgroups. For more information, see Creating a Data Set Using Amazon Athena Data and Benefits of Using Workgroups.
About the Author
Avijit Goswami is a Sr. Startups Solutions Architect at AWS, helping startup customers become tomorrow’s enterprises. When not at work, Avijit likes to cook, travel, watch sports, and listen to music.