英文:
How to properly use s3 to deliver and store files in a web application?
问题
- 如果网站需要图片,请求应该首先访问我们的服务,然后从S3获取图片(反向代理),还是客户端直接请求文件?
- 如何隐藏文件名、路径名以及在文件请求中管理权限?
- 上传新内容时是否适用相同的问题?
- 处理S3的配额和并发请求。
英文:
So we are planning to move static content to s3 for operational reasons. I just want to understand where to place s3 in the workflow of handling a request.<br>
- If website requires an image, should the request hit our service first which would fetch the image from s3 (reverse-proxy) or should client directly request the file.
- How to hide file names ,pathnames and manage permissions in request for file?
- Same questions applicable for uploading new content.
- Handle s3 quota and parallel requests
答案1
得分: 1
我本打算进行评论,但结果变成了一个完整的答案…
-
两者皆可。如果您的资产是公开的,最轻量的方法是直接从公共S3存储桶中请求它们。但如果它们不是公开的,使用CloudFront可能比自行在S3请求周围进行身份验证更容易。
-
您可以使得位于
S3.yourBucket/A.jpeg
的资源A.jpeg
看起来就像位于yourWebsite.com/A.jpeg
一样使用CloudFront。如果您还想模糊文件名A
,您需要使用例如 API 网关,向前端提供文件,而不会透露任何关于它的信息。如果是我,我可能不会这么麻烦。 -
除非绝对必要,不要让用户上传到其他用户从中下载的同一个存储桶。根据用例,有几种上传方法。预签名 URL 非常适用于一次性使用。您还可以通过使用 Cognito,向用户提供只允许写入上传存储桶的 AWS 凭证。
-
没有 S3 配额限制。您将根据读取和写入付费。对于简单的网站,这些费用将非常小。如果您担心,您可以使用 CloudFront 为用户设置速率限制。您还可以使用 API Gateway 为各个用户创建限制。S3 可以非常并行化。
英文:
I was going to comment, but this turned into a full answer instead...
-
Either. If your assets are public, the lowest-weight method is to just request them from a public S3 bucket. If they're not, though, it's probably easiest to use Cloudfront rather than rolling-your-own auth around S3 requests.
-
You can make it look like your asset
A.jpeg
inS3.yourBucket/A.jpeg
is atyourWebsite.com/A.jpeg
using Cloudfront. If you want to also obscure the filenameA
, you need to use e.g. API gateway to serve you the file without revealing anything about it to your front end. If it were me, I wouldn't bother. -
Unless you absolutely have to, don't let users upload to the same bucket that other users download from. There are several approaches to uploads depending on the use-case. Pre-signed URL's are good for one-time use. You can also just provide the user with AWS credentials that are allowed to write-only to the upload bucket, by using Cognito.
-
There's no S3 quota. You get charged for reads and writes. For a simple site, these charges will be tiny. If you're worried, you can use Cloudfront to rate-limit your users. You can also use API Gateway to create limits for individual users. S3 is extremely parallelizable.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论