aws-profile-handler
v2.0.3
Published
dealing with aws credentials a little bit eaiser
Downloads
8,309
Readme
aws-profile-handler
Simply tool for extracting and editing the .aws/credentials. You can add, get, list, and delete profile(s) synchronously, no 3p dependencies introduced.
How do I install it?
Install it into your package
npm install aws-profile-handler --save
Add a profile
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
Get a profile's credentials
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"
}
List profiles
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'];
Delete a profile
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');
Error
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.'
Note:
Version 1.X.X is deprecated, the last V1 update was 1.1.0.