node.js - AWS:无法使用流从 SSE-KMS 加密存储桶下载文件
问题描述
我有一个配置了启用加密的存储桶:
我有使用流在 S3 存储桶上上传/下载文件的 nodejs 项目。问题是我可以成功上传,但是当我尝试使用流下载/获取文件时,它只发出一次“数据”事件,然后发出“结束”事件,但仍有数据可以消耗从下面的日志中看到。你知道为什么会这样吗?
附加信息:
- 当我上传到没有启用加密的存储桶时,它工作正常。
- 我的政策有“kms:Decrypt”
- 我尝试使用 aws cli 上传和下载,并且成功。
- 我们使用 s3.getSignedUrl('getObject', params) 创建文件 URL
- 使用 request.js
下载流:
async downloadStream() {
logger.info('Getting download stream...');
const url = await this.getFileUrl(); // getSignedUrl
const headers = {};
this.downloadStream = request({ url, headers });
this.downloadStream.on('data', (chunk) => this.emit('data', chunk.length));
this.downloadStream.on('end', () => this.emit('end'));
this.downloadStream.on('error', (error = {}) => this.emit('failure', error));
logger.info('Acquired download stream successfully');
this.downloadStream.pipe(this.response);;
}
记录信息:
完整传输统计:
传输的字节数:13170 字节中的 4491 个剩余字节
:8679
平均块大小:4491 字节
估计剩余块:2
平均速度:0.000260375 MB/s 总传输时间:13.127 秒
解决方案
在服务器端使用 KMS 加密的对象在访问它们时需要使用 SigV4 协议。 来源:aws论坛
创建 AWS.S3 客户端时,在选项中添加 signatureVersion: 'v4':
return new aws.S3({
credentials,
params: {
bucket,
},
region,
signatureVersion: 'v4',
});
这解决了我的问题。
推荐阅读
- python - 如何为特定数据而不是每个数据设置 xticks 标签?
- python - Python Flask Application Context,如何将应用程序暴露给其他模块
- spring - 如何避免通过配置进行配置?
- ios - 在我的应用程序顶部看不到时间,因为顶部栏是暗的
- java - Intellij - 无法在项目 *** 上执行目标 org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test) :有测试失败
- markdown - 降价中 Liquid 过滤器的 Sublime Text 语法高亮问题
- java - JavaFX 阶段 * 有时 * 在 Win10 上显示为空白
- android - 模拟一个按钮按下另一个按钮按下
- laravel - 如何更新 Laravel 中的别名列
- java - 自定义插件不会出现在 Minecraft 中?