Amazon QuickSight 嵌入式仪表板 - 如何在我的网络应用程序中缓存用户会话(计费和时间问题)

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

我使用 amazon-quicksight-embedding-sdk(遵循 https://learnquicksight.workshop.aws/en/dashboard-embedding.html)在我的 Web 应用程序中嵌入了 Amazon QuickSight 控制面板。

https://docs.aws.amazon.com/quicksight/latest/APIReference/API_GetDashboardEmbedUrl.html 中所述,用户会话似乎持续了许多小时 当我直接从我的网络浏览器请求嵌入 URL 时,我可以看到它在很多小时内有效。

但是我的网络应用程序会在用户重新启动时请求新的嵌入 URL(通过 closing/reopening tab/browser)。这是否意味着新的用户会话已创建并计费。

是否可以存储嵌入 URL 并在同一用户关闭 tab/browser 并打开网络应用程序和再次仪表板(当然在同一个浏览器中)?

我尝试将嵌入URL 存储为名为“embed_url”的 cookie。但是调用 amazon-quicksight-embedding-sdk.embedDashboard({url: embed_url}) 结果是

"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."

我确信 embed_url 仍然有效,因为通过浏览器直接请求它有效。 上面的错误信息中提到了哪个“授权码”?我错过了什么或者实际上不可能吗?

除了计费问题,我注意到获取嵌入的调用URL 花费了时间(超过 5 秒,eu-central-1),而嵌入花费的时间更少(3 秒)。我认为我可以通过重用获得的嵌入 URL 来缩短仪表板加载时间。对时间有什么意见吗?这是正常的还是我做错了什么所以它这么慢?我的测试仪表板只有 1 个图表,数据集未更改。

根据 Quicksight Pricing Page,如果您要为 Quicksight“Reader”创建嵌入式仪表板,则每 30 分钟登录会话的费用为 0.30 美元/会话为此 Reader.

session的有效期可以在GetDashboardEmbedUrlAPI的SessionLifetimeInMinutes参数中设置,上限为600分钟(10小时)。

例如,假设您将 Reader 用户的 SessionLifetimeInMinutes 设置为 600 分钟。还假设该用户保持登录状态并连续使用仪表板 10 小时,那么这相当于使用了 20 次会话(因为计费是以 30 分钟为增量)。乍一看,这似乎会导致 $0.30/session * 20 session-chunks = $6 被计费。

但是,根据定价页面,每个 Reader 的上限为每月 5.00 美元。这意味着这个 Reader 永远不会超过每月 5 美元,无论为他们创建了多少个 Quicksight 会话(无论持续时间如何)。因此,无论您为给定 Reader 调用 GetDashboardEmbedUrl API 多少次,该用户每月的费用上限为 5 美元。

还用于 Reader 会话的构成(来自定价页面):

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.

我对此不是 100% 确定,但是是的,我相信刷新(或 open/close)选项卡会导致同一用户的新会话。

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.

以上摘录自定价页面。因此,页面刷新(以及对 GetDashboardEmbedUrl 的另一次调用)似乎确实会为用户触发一个新会话。

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

GetEmbedDashboardUrl API 响应是一个 JSON 对象,如下所示:

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

如果仔细观察 EmbedUrl,除了仪表板 url 本身,还有这些查询字符串参数:

  • isauthcode
  • 代码
  • 身份提供者
  • statePersistenceEnabled
  • 可能:还有其他参数

code 参数(嵌入在 embedUrl 中)是您询问的“授权码”。

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)?

不,这是不可能的。正如 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.

因此,embedURL 及其关联的授权码只能一起使用一次。这是有道理的,因为这将防止 MITM 重放攻击等场景。此外,我实际上尝试缓存响应,然后在缓存命中的情况下重新使用 embedUrl,因为这会改善最终用户体验。但这没有用 - 正如他们的文档中提到的那样,QuickSight 阻止了 embedUrl 的“重播”。

Any comments about the timing?

这也是我们的经验。我们的应用程序 GetDashboardEmbedUrl REST API 大约需要 5-7 秒 (us-east-1),然后实际嵌入还需要 3-5 秒。不太好,但我目前还没有找到解决这种糟糕用户体验的方法。