-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support for AWS_PROFILE #12
Comments
@FLemon Since this issue is still open a year later I thought I would share my solution to this using const AWS = require('aws-sdk');
const S3BrowserDirectUpload = require('s3-browser-direct-upload');
AWS.config.getCredentials(err => {
if (err) {
throw err;
}
const { accessKeyId, secretAccessKey } = AWS.config.credentials;
const s3 = new S3BrowserDirectUpload({
accessKeyId,
secretAccessKey,
region: 'us-east-1',
});
s3.uploadPostForm({
bucket: 'mybucket-dev',
region: 'eu-west-2',
key: 'fsociety.txt',
extension: 'txt',
acl: 'private',
contentLength: 1024,
}, (err, data) => {
if (err) {
throw err;
}
console.log(data);
// { params:
// { key: 'fsociety.txt',
// acl: 'private',
// 'x-amz-algorithm': 'AWS4-HMAC-SHA256',
// 'x-amz-credential': '### ### ### ###',
// 'x-amz-date': '### ### ### ###',
// policy: '### ### ### ###',
// 'x-amz-signature': '### ### ### ###',
// 'content-type': 'text/plain' },
// public_url: 'https://mybucket-dev.s3.amazonaws.com/fsociety.txt',
// form_url: 'https://mybucket-dev.s3.amazonaws.com/' }
});
}); Since the above code just uses credentials just like internal AWS SDKs do, this works for |
Update: If you're using an IAM role with this, you'll need to include the const AWS = require('aws-sdk');
const S3BrowserDirectUpload = require('s3-browser-direct-upload');
AWS.config.getCredentials(err => {
if (err) {
throw err;
}
const { accessKeyId, secretAccessKey, sessionToken } = AWS.config.credentials;
const s3 = new S3BrowserDirectUpload({
accessKeyId,
secretAccessKey,
region: 'us-east-1',
});
s3.uploadPostForm({
bucket: 'mybucket-dev',
region: 'eu-west-2',
key: 'fsociety.txt',
extension: 'txt',
acl: 'private',
contentLength: 1024,
conditionMatching: [
{ 'x-amz-security-token': sessionToken }
],
}, (err, data) => {
if (err) {
throw err;
}
data.params['x-amz-security-token'] = sessionToken;
console.log(data);
// { params:
// { key: 'fsociety.txt',
// acl: 'private',
// 'x-amz-algorithm': 'AWS4-HMAC-SHA256',
// 'x-amz-credential': '### ### ### ###',
// 'x-amz-security-token': '### ### ### ###',
// 'x-amz-date': '### ### ### ###',
// policy: '### ### ### ###',
// 'x-amz-signature': '### ### ### ###',
// 'content-type': 'text/plain' },
// public_url: 'https://mybucket-dev.s3.amazonaws.com/fsociety.txt',
// form_url: 'https://mybucket-dev.s3.amazonaws.com/' }
});
}); Even though "sessionToken" is supported by the constructor in this library, it checks that the sessionToken is an instance of AWS.config, rather than a string, and therefore cannot be used 🤦♂ |
... Anyone coming here from Google: Use |
hi, do you have plan to support
AWS_PROFILE
as alternative tokey_id & access_key
?The text was updated successfully, but these errors were encountered: