我们如何在 Web 浏览器中使用 AWS Kinesis?

How can we use AWS Kinesis in a web browser?

我们如何在 Web 浏览器中使用 AWS Kinesis?

我对 AWS Kinesis Stream 很感兴趣,想知道我是否可以使用它来将用户的 activity 日志直接从他们的浏览器发送到 AWS。

A​​WS 提供 a JavaScript SDK 可在 Web 浏览器中执行,但根据其文档,SDK 需要凭据信息,因此我认为在我的用例中使用它并不安全。

我应该在他们的浏览器和 AWS Kinesis 之间放置代理服务器吗? 或者在这种情况下有什么安全的方法可以使用 AWS Kinesis 吗?

您有几个选项可以直接从用户的浏览器使用 JS SDK,而无需在您的代码中嵌入凭据或强制您的用户登录服务:

第一个是使用AWSCognito. You can embed couple of line of code in your JS code that will identify the identity pool you want to use. On the service side you define the role for unauthenticated users to be able to write to Kinesis. You can see more details in this blog post: https://blogs.aws.amazon.com/javascript/post/Tx1F7FO6GDAIXD3/Authentication-with-Amazon-Cognito-in-the-Browser

第二个选项是 API-Gateway between your users and the Kinesis stream. The gateway is a managed service that you can define as "open" with no authentication and the gateway can be the one with the permission to write to your Kinesis stream. The simplest way is to use a Lambda function that will be able also to transform/clean the events before putting them to the stream. See more details in the service documentations: http://docs.aws.amazon.com/apigateway/latest/developerguide/getting-started.html