使用适用于节点的 AWS 开发工具包将 S3 资源 public 设为只读一段时间?

Make a S3 resource public read-only for some duration using the AWS SDK for node?

我已将 S3 集成到我的节点应用程序并将某些文档上传到 S3。需要与第三方共享这些文件。 通过 API 将 URL 发送给第三方,他们会立即下载。我想让 S3 对象 public 持续一段时间。我如何实现这一目标?

S3 presigned URL 是您要找的,您可以使用它们为您的第三方生成带有到期时间的链接。我在下面发布参考链接

Presigned url AWS official documentation

A blog post which demonstrate presigned urls further

在@varnit 的帮助下,我能够弄清楚在一定时间内创建 public URL。 我有另一个问题,从资源 URL 获取 KEY。

解决了在 Node 中使用这个:

AmazonS3URI(resourceUrl) 

其中 returns 是这样的:

{  
   "uri":{  
      "protocol":"https:",
      "slashes":true,
      "auth":null,
      "host":"bucket.s3.region.amazonaws.com",
      "port":null,
      "hostname":"bucket.s3.region.amazonaws.com",
      "hash":null,
      "search":null,
      "query":null,
      "pathname":"/private/region%xxxxxx/file",
      "path":"/private/region%xxxxx/file",
      "href":"https://bucket.s3.region.amazonaws.com/private/region%xxxxxx/file"
   },
   "isPathStyle":false,
   "bucket":"aaaa-bbbb-ccc",
   "key":"private/xxxxx:yyyyy/file",
   "region":"region"
 }