amazon-web-servicesdashboardquicksight-embeddingamazon-quicksight

Amazon QuickSight embedded dashboard - how to cache user session in my webapp (billing and timing concern)


I have embedded Amazon QuickSight dashboard in my web application by using amazon-quicksight-embedding-sdk (followed https://learnquicksight.workshop.aws/en/dashboard-embedding.html).

The user session seems to last many hours as mentioned in https://docs.aws.amazon.com/quicksight/latest/APIReference/API_GetDashboardEmbedUrl.html When I requested the embed URL directly from my web browser, I could see that it was valid for many hours.

But my web app will request a new embed URL when user restarts it (by closing/reopening tab/browser). Does that mean a new user session was created and billed.

Is it possible to store the embed URL and to reuse it (as long as the user session lasts) for the case the same user closes the tab/browser and open the web app and the dashboard again (of course in the same browser)?

I tried to store the embedURL as a cookies named "embed_url". But calling amazon-quicksight-embedding-sdk.embedDashboard({url: embed_url}) resulted in

"Embedding failed because of invalid URL or authorization code. Both of these must be valid and the authorization code must not be expired for embedding to work."

I was sure the embed_url was still valid because requesting it by the browser directly worked. Which "authorization code" is mentioned in the above error message? What did I miss or is it actually not possible?

Beside the billing concern, I've noticed that the call to get the embedURL took time (more than 5 seconds, eu-central-1) while the embedding took less (3 seconds). I thought I could improve the dashboard loading time by reusing the gotten embedURL. Any comments about the timing? Is it normal or did I do something wrong so that it was so slow? My test dashboard has only 1 diagram with unchanged dataset.


Solution

  • As per the Quicksight Pricing Page, if you're creating an embedded dashboard for a Quicksight "Reader", then you're paying $0.30/session per 30-minute logged-in-session for this Reader.

    The validity of the session can be set in the SessionLifetimeInMinutes parameter of the GetDashboardEmbedUrl API, and has an upper bound of 600 minutes (10 hours).

    As an example, suppose you set SessionLifetimeInMinutes to 600 mins for your Reader user. Also suppose that this user stayed logged in and uses the dashboard for 10 hours continuously, then that would equate to 20 sessions of usage (since the billing is in increments of 30-min chunks). At first glance it would seem that this would cause $0.30/session * 20 session-chunks = $6 to be billed.

    However, as per the pricing page, there is an upper bound of $5.00 per month for every Reader. Which means that this Reader can never exceed $5 per month regardless of how many Quicksight sessions (of whatever duration) are created for them. So no matter how many times you call the GetDashboardEmbedUrl API for a given Reader, you're capped to $5/month for this user.

    Also of use as to what constitutes a Reader session (from the pricing page):

    When does a Reader Session start and end?
    
    A Reader Session starts with user-initiated action (e.g., login, dashboard load, page refresh, drill-down or filtering) and runs for next 30-minutes.
     
    Keeping Amazon QuickSight open in a background browser window/tab does not result in active sessions until the Reader initiates action on page.
    

    But my web app will request a new embed URL when user restarts it (by closing/reopening tab/browser). Does that mean a new user session was created and billed.

    I'm not 100% sure about this, but yes I believe a refresh (or open/close) of the tab results in a new session for the same user.

    A Reader Session starts with user-initiated action (e.g., login, dashboard load, page refresh, drill-down or filtering) and runs for next 30-minutes.

    The above excerpt is from the pricing page. So it does seem that page refresh (and thus another call to GetDashboardEmbedUrl) will trigger a new session for the user.

    Which "authorization code" is mentioned in the above error message?

    The GetEmbedDashboardUrl API response is a JSON object that looks like this:

    {
        "Status": 200,
        "EmbedUrl": "https://us-east-1.quicksight.aws.amazon.com/embed/f4147cd0d4d_BLAH_BLAH_...",
        "RequestId": "c15a7bad-629e-444a-b643-ff3142c9ae41"
    }
    

    If you look closer at the EmbedUrl, apart from the dashboard url itself, there are also these query-string parameters:

    The code parameter (embedded within the embedUrl) is the "authorization code" that you asked about.

    Is it possible to store the embed URL and to reuse it (as long as the user session lasts) for the case the same user closes the tab/browser and open the web app and the dashboard again (of course in the same browser)?

    No, that can't be done. As it says in the link you shared:

    The following rules apply to the combination of URL and authorization code:
    
    - They must be used together.
    - They can be used one time only.
    - They are valid for 5 minutes after you run this command.
    

    So the embedURL and its associated auth code can only be used once together. Makes sense since this will prevent MITM replay attacks among other scenarios. Also I actually tried to cache the response and then re-use the embedUrl in case of a cache-hit, since this would improve the end-user experience. But this didn't work - a "replay" of the embedUrl is blocked by QuickSight, as mentioned in their doc.

    Any comments about the timing?

    This has been our experience also. The GetDashboardEmbedUrl REST API takes around 5-7 seconds (us-east-1) for our app and then the actual embedding takes another 3-5 seconds. Not great, but I don't see a way around this poor user experience as of now.