Simply tool for extracting and editing the .aws/credentials. You can add, get, list, and delete profile(s) synchronously, no 3p dependencies introduced.
Install it into your package
npm install aws-profile-handler --save
let valid_credential_object = {
"aws_access_key_id": "123",
"aws_secret_access_key": "456"
};
let awsProfiler = require('aws-profile-handler');
// AWS credentials file path is optional as the last parameter. Default to ~/.aws/credentials
awsProfiler.addProfile('awesomeProfileName', valid_credential_object);
awsProfiler.addProfile('awesomeProfileName', valid_credential_object, 'file/path/to/aws/credentials');
// .aws/credentials
[awesomeProfileName]
aws_access_key_id=123
aws_secret_access_key=456
let awsProfiler = require('aws-profile-handler');
// AWS credentials file path is optional as the last parameter. Default to ~/.aws/credentials
awsProfiler.getProfileCredentials('awesomeProfileName');
awsProfiler.getProfileCredentials('awesomeProfileName', 'file/path/to/aws/credentials');
// return 'null' if profile doesn't exist
// return an object with 'aws_access_key_id' and 'aws_access_key_id'
{
"aws_access_key_id": "123",
"aws_secret_access_key": "456"
}
let awsProfiler = require('aws-profile-handler');
// AWS credentials file path is optional as the last parameter. Default to ~/.aws/credentials
awsProfiler.listProfiles();
awsProfiler.listProfiles('file/path/to/aws/credentials');
// return a list of all the profiles' name
// ['awesomeProfileName', 'something', 'else', 'if', 'exists'];
let awsProfiler = require('aws-profile-handler');
// AWS credentials file path is optional as the last parameter. Default to ~/.aws/credentials
awsProfiler.deleteProfile('lameProfileName');
awsProfiler.deleteProfile('lameProfileName', 'file/path/to/aws/credentials');
Four customized errors would be thrown.
- If format is invalid.
// error.message:
'Invalid AWS credential file. Cannot have nested sessions'
- If one or more values are missing.
// .aws/credentials
[badProfile]
aws_access_key_id=
aws_secret_access_key=idIsMissing
// error.message
'Invalid AWS credential file. Incomplete key/value pair'
- If input credentials object is invalid.
let missingOneKey = {
aws_access_key_id: 1
}
let haveOneExtraKey = {
aws_access_key_id: 1,
aws_secret_access_key: 2,
extra: 3
}
let wrongName = {
aws_secret_access_key: 2,
extra: 3
}
// error.message
'Invalid input: credentials schema is invalid.'
- If require input parameters are missing.
awsProfileHandler.addProfile();
// error.message
'Invalid Input: profile name cannot be omitted nor only contains white spaces.'
awsProfileHandler.addProfile('profile');
// error.message
'Invalid Input: credentials cannot be omitted nor empty.'
Version 1.X.X is deprecated, the last V1 update was 1.1.0.