I'm trying to upload some files on a S3 bucket, it works with the hardcoded credentials but I wanted to push the security a little bit further by using IAM Roles instead.
Here's what I did :
- Create an IAM Role enabling full access to a specific S3 bucket
- Added the role to the EC2 instane running my app
- Made a call with AWS SDK not specifying credentials (Assuming the role)
- Had an error
Here's the code I used for the S3 interactions
const AWS = require('aws-sdk');
const s3 = new AWS.S3();
const options = {
Bucket: BUCKET_NAME,
Key: /my/key/
Body: mybody,
ContentType: somecontent,
ACL: 'public-read'
};
return s3.upload(options, (err, data) => {
if (err) {
return reject(err);
}
//code continue
});
And here's what i've got :
CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
So I tried to use config files at ~/.aws/config and ~/.aws/credentials (I also set AWS_SDK_LOAD_CONFIG to one in my .bashrc file and set the config file paths).
.aws/config :
[default]
region=myregion
role_arn=myrolearn
Also tried with the credentials in the file so that at least it wont appear in the code itself.
Am I missing something?
Thanks in advance
question from:
https://stackoverflow.com/questions/65938302/node-js-aws-sdkmissing-credentials-on-upload-to-s3-assuming-iam-role 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…