Я пытаюсь сгенерировать URL-адрес PresignedPost с помощью AWS javascript sdk,
Я получаю следующую ошибку -
Error: Unable to create a POST object policy without a bucket, region, and credentials
У меня настроены учетные данные AWSмой локальный с доступом S3,
В коде я задаю регион при создании клиента S3,
при передаче имени сегмента в качестве параметра клиентскому методу.
Ниже приведенфрагмент кода -
const AWS = require('aws-sdk');
let util = require('util');
let s3Client = new AWS.S3({
region: 'us-east-1'
});
let postSignedUrl = async () => {
try {
let postSigningParams = {
Expires: 60,
Bucket: "some-bucket-name,
Conditions: [["content-length-range", 100, 10000000]],
Fields: {
key: 'test/image.jpg'
}
}
let s3createPresignedPost = util.promisify(s3Client.createPresignedPost).bind(s3Client);
let postSignedUrl = await s3createPresignedPost('putObject',postSigningParams);
console.log('postSigningParams => ', postSignedUrl);
} catch (error) {
console.error(error);
}
}
postSignedUrl();
Трассировка стека ошибок -
Error: Unable to create a POST object policy without a bucket, region, and credentials
at features.constructor.preparePostFields (/Users/aniruddhanarendraraje/Documents/work/pocs/node-crud-app/snippets/node_modules/aws-sdk/lib/servi
ces/s3.js:943:13)
at finalizePost (/Users/aniruddhanarendraraje/Documents/work/pocs/node-crud-app/snippets/node_modules/aws-sdk/lib/services/s3.js:906:22)
at /Users/aniruddhanarendraraje/Documents/work/pocs/node-crud-app/snippets/node_modules/aws-sdk/lib/services/s3.js:923:24
at finish (/Users/aniruddhanarendraraje/Documents/work/pocs/node-crud-app/snippets/node_modules/aws-sdk/lib/config.js:349:7)
at /Users/aniruddhanarendraraje/Documents/work/pocs/node-crud-app/snippets/node_modules/aws-sdk/lib/config.js:367:9
at SharedIniFileCredentials.get (/Users/aniruddhanarendraraje/Documents/work/pocs/node-crud-app/snippets/node_modules/aws-sdk/lib/credentials.js:
127:7)
at getAsyncCredentials (/Users/aniruddhanarendraraje/Documents/work/pocs/node-crud-app/snippets/node_modules/aws-sdk/lib/config.js:361:24)
at Config.getCredentials (/Users/aniruddhanarendraraje/Documents/work/pocs/node-crud-app/snippets/node_modules/aws-sdk/lib/config.js:381:9)
at features.constructor.createPresignedPost (/Users/aniruddhanarendraraje/Documents/work/pocs/node-crud-app/snippets/node_modules/aws-sdk/lib/ser
vices/s3.js:918:14)
at Promise (internal/util.js:274:30)
Я попробовал следующее, но не сработало -
AWS.config.update({region:'us-east-1'});
let s3Client = new AWS.S3();
Аналогичный метод AWS S3 SDK работает -
let presignedUrl = async () => {
let signingParams = {
Bucket: 'some-bucket-name',
Key: 'test/image.jpg',
Expires: 60
}
let s3GetSignedUrl = util.promisify(s3Client.getSignedUrl).bind(s3Client);
let signedUrl = await s3GetSignedUrl('putObject',signingParams);
console.log('signedUrl => ', signedUrl);
}