Sunday, December 31, 2023

AWS - Get quicksight embed url using JavaScript SDK V3

In the realm of data-driven solutions, AWS QuickSight offers a robust platform for crafting dynamic and insightful dashboards. Embedding these dashboards directly into your applications adds a layer of accessibility and convenience. This guide walks you through the process of obtaining a secure QuickSight embed URL using JavaScript SDK V3, suitable for both Node.js backend and Lambda functions. Before proceeding, ensure your QuickSight dashboard is created and shared with the intended audience.

Prerequisites:

Make sure you've completed the following preliminary steps:

Dashboard Setup:
    
Create your QuickSight dashboard and Share the dashboard with all users in your AWS account.



















Domain Whitelisting:

Whitelist the domain where you plan to embed the QuickSight dashboard

    









Step 1: IAM Role Creation with Required Policies

To interact with QuickSight, set up an IAM role with specific permissions. Include the following policies in your IAM role: quicksight:RegisterUser and quicksight:GetDashboardEmbedUrl.

Step 2: Assuming IAM Role Using AWS SDK

Assume the IAM role you created using the AWS SDK.

Step 3: Register a User in QuickSight

Before obtaining the embed URL, register a user in QuickSight. Note that this is a one-time process; subsequent calls will result in an error.

This will create a QuickSight user, as shown below:









Step 4: Retrieve Secure QuickSight Dashboard Embed URL

Fetch the secure QuickSight dashboard embed URL using the following code snippet:

Complete Lambda Function Code:

Here is the complete Node Lambda function code, seamlessly integrating all the steps discussed above:

Make sure to add following npm package @aws-sdk/client-sts and @aws-sdk/client-quicksight