我有一个 .json 文件存储在 S3 存储桶中,现在我想用 nodejs 下载 json 文件。我写了以下代码:
const bucket = "s3bucketname";
const AWS = require('aws-sdk');
const S3= new AWS.S3();
exports.handler = async (event, context, callback) => {
var transcript = await download();
console.log(transcript);
}
async function download(){
try {
// Converted it to async/await syntax just to simplify.
const data = await S3.getObject(
{ Bucket: bucket,
Key: "Test.json",
//ResponseContentType: 'application/json'
}).promise();
console.log(data);
return {
statusCode: 200,
body: JSON.stringify(data)
}
}
catch (err) {
return {
statusCode: err.statusCode || …Run Code Online (Sandbox Code Playgroud)我目前正在使用该serverless-s3-sync插件将本地目录同步到 S3 存储桶中。
我的代码如下所示serverless.yml:
custom:
s3Sync:
- bucketName: mydestintationBucket
localDir: .
acl: public-read
Run Code Online (Sandbox Code Playgroud)
我的问题是我不想将整个目录同步到 S3 存储桶。有没有办法只定义特定的文件夹/文件以同步到S3,或者有更好/其他的方法来做到这一点(例如另一个插件)?