我正在尝试从aws s3存储桶中获取对象,但数据响应为空。 我的代码如下:
import * as AWS from 'aws-sdk';
public async getObjects() {
AWS.config.update({
accessKeyId: "MY_KEY_ID",
secretAccessKey: "MY_SECRET_KEY",
region: "eu-central-1"
});
let s3 = new AWS.S3();
const response = await s3.listObjects({Bucket: 'my-bucket'});
console.log(response);
}
我从调试器得到的响应:
response:
Response {
request: [Circular],
data: null,
error: null,
retryCount: 0,
redirectCount: 0,
httpResponse:
HttpResponse {
statusCode: undefined,
headers: {},
body: undefined,
streaming: false,
stream: null },
maxRetries: 3,
maxRedirects: 10 }
答案 0 :(得分:1)
s3.listObjects
不返回诺言,您应以其他方式调用它(https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#listObjects-property):
import * as AWS from 'aws-sdk';
public getObjects() {
AWS.config.update({
accessKeyId: "MY_KEY_ID",
secretAccessKey: "MY_SECRET_KEY",
region: "eu-central-1"
});
let s3 = new AWS.S3();
s3.listObjects({Bucket: 'my-bucket'}, (err, data) => {
if (err) console.log(err, err.stack);
else console.log(data);
});
}