如何显示非公开的s3存储桶中的对象

如何显示非公开的s3存储桶中的对象

本文介绍了如何显示非公开的s3存储桶中的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试显示非公开的S3存储桶中的对象。为此,我必须向AWS提供访问密钥和密钥。

I am trying to show objects from an S3 bucket that is not public. In order to do this I would have to provide the access and secret keys to AWS.

我有这个小提琴(没有键)但是当我输入正确的键时它不起作用:

I have this fiddle (without the keys) but it does not work when I enter the correct keys: http://jsfiddle.net/jsp3wzbu/

<section ng-app data-ng-controller="myCtrl">
    <img  ng-src="{{s3url}}" id="myimg">
</section>

此外,如何处理安全性?我不想将访问/密钥存储在我的客户端代码中,因为用户会看到它。我的服务器代码将这些密钥保存在环境变量中,我担心如果我与客户端JS代码共享它们,那么它们将被公开。我还有其他方法可以在浏览器上显示S3对象吗? ....服务器可以提供图像作为base64 json并且客户端代码呈现吗?

also, how is security handled? I would not want to store the access/secret keys in my client code because users will see it. My server code keeps these keys in environment variables and I fear that if I share them with my client side JS code, then they will be exposed. Is there any other way for me to show the S3 object on the browser? ....Can the server provide the images as base64 json and the client side code renders it?

推荐答案

这是我的方法提供对私有S3存储桶内容的访问。

Here is how I handle providing access to the contents of a private S3 bucket.


  1. 我为我的EC2实例使用IAM角色。我没有在EC2实例上存储AWS凭据。

  2. 我要求用户登录。您可以使用家庭酿造登录设置(数据库),Cognito或其他IDP(如Google或Facebook)。

  3. 从我的后端代码中,我生成的预签署URL将在15分钟后到期。如果URL是针对大文件的,我会根据文件大小调整超时,假设Internet连接速度较慢。

  4. 在我的HTML页面的JavaScript中,我刷新了15分钟之前的URL到期(通常通过AJAX每5分钟)。这可以通过简单的刷新页面或(更好)通过使用AJAX刷新URL来完成。这样可以处理长时间打开页面的用户。

  1. I use IAM roles for my EC2 instances. I do not store AWS credentials on the EC2 instance.
  2. I require the user to login. You can use a home brew login setup (database), Cognito or another IDP such as Google or Facebook.
  3. From my back-end code I generate presigned URLs that expire in 15 minutes. If the URLs are for large files, I adjust the timeout to be longer based upon the size of the file assuming a slow Internet connection.
  4. In the JavaScript for my HTML pages, I refresh the URLs before the 15 minutes expires (usually every 5 minutes via AJAX). This can be done via a simple refresh page or (better) by using AJAX to just refresh the URLs. This handles users that leave a page open for a long period of time.

这篇关于如何显示非公开的s3存储桶中的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 13:06