amazon-s3 - AWS Lambda 从 S3 获取文件然后使用它
问题描述
我需要从我的 S3 中提取 2 个文件并在 HttpAgent 中使用它们,我努力寻找正确的方法。使用返回 ReadableStream 的 SDKv3。
const { Readable } = require('stream');
const { createWriteStream } = require('fs');
const { S3Client, GetObjectCommand } = require('@aws-sdk/client-s3');
async (event, context) => {
let options;
let httpsAgent;
try {
console.log('> Getting content from S3');
const s3Client = new S3Client({
region: 'us-east-2',
});
let command = new GetObjectCommand({
Key: 'lib/myCert.crt',
Bucket: 'mybucket',
});
console.log('>>Getting Cert command');
const hcert = await s3Client.send(command);
command = new GetObjectCommand({
Key: 'lib/myKey.pem',
Bucket: 'mybucket',
});
console.log('Get Key');
const ckey = await s3Client.send(command);
console.log('initializing Agent');
httpsAgent = new https.Agent(
{
key: ckey.Body.pipe(createWriteStream('/tmp/myKey.pem')),
cert: hcert.Body.pipe(createWriteStream('/tmp/myCert.crt')),
// key: fs.readFileSync('./tmp/myKey.pem'),
// cert: fs.readFileSync('./tmp/myCert.crt'),
keepAlive: true
}
);
使用上面的代码,我得到了一个 ParameterNotFound。我尝试写入磁盘然后访问(通过 fs.ReadFileSync)但同样的问题。
解决方案
推荐阅读
- php - AWS 部署中的 Dialogflow 崩溃
- mybatis - 在mybatis中插入hashmap key和value
- python - 我不明白错误消息'NoneType' object is not iterable in python
- javascript - 使用 FB API 从 Facebook 页面获取帖子
- assembly - 有人可以解释这个汇编语言程序来查找字符串的反转吗?在 read() 之后是否未初始化使用 RAX?
- amazon-web-services - 私有 VPC 中的 Lambda 需要很长时间才能使用 S3 API
- java - 解锁手机后重新启动应用程序覆盖
- for-loop - 如何使用循环插入面板数据中的值
- java - 我可以在服务 bean 中有公共静态字段吗?
- c++ - 在主函数的参数括号中使用 void 进行函数重载