npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

get-aws-profiles

v1.1.0

Published

Returns the list of AWS profiles available on the local machine using AWS-SDK native private methods

Downloads

10

Readme

Get-AWS-Profiles

Returns the list of AWS profiles available on the local machine using AWS-SDK native private methods.

Why?

In one of my recent projects ( The Log-Gage! ) I needed to get a list of available AWS profiles from the local machine, after studying AWS-SDK, I realized that there are private methods available to do this on the official SDK but of-course none was exposed ( For understandable reasons I guess ), so I wrote this very light shell-package to surface those useful methods, so if you, like me, were extending AWS tools or creating a new one can leverage the existing SDK and have your code-base more focused on what it does.

Getting Started

This Module and its main dependency ( AWS-SDK ) rely on node APIs and will not work in a browser.

Installing

npm i --save get-aws-profiles

Usage

First require / import it:

const awsProfiles = require('get-aws-profiles');

get( ):

returns the whole credentials object;

console.log( awsProfiles.get() );
/* output format:
{
    default: {aws_access_key_id: 'aws_access_key_id', aws_secret_access_key: 'aws_secret_access_key'},
    work: {aws_access_key_id: 'aws_access_key_id', aws_secret_access_key: 'aws_secret_access_key'},
    mim: {aws_access_key_id: 'aws_access_key_id', aws_secret_access_key: 'aws_secret_access_key'},
    ...
}
 */

use( ):

Then you can use the use method to get a credentials object that you can pass to the AWS.config. You just need to pass the name of one of the profiles you get from the get method:

AWS.config.credentials = awsProfiles.use('profile_name');
/* output format:
 {
  expired: false,
  expireTime: null,
  refreshCallbacks: [],
  accessKeyId: 'xxx',
  sessionToken: undefined,
  filename: undefined,
  profile: 'default',
  disableAssumeRole: false,
  preferStaticCredentials: false,
  tokenCodeFn: null,
  httpOptions: null }
 */

getDefaultFilepath( ):

returns the path to the credentials file in the current system/os:

console.log(awsProfiles.getDefaultFilepath());
// output format: "/Users/mimarmand/.aws/credentials"

getProfile( ):

returns the credentials of the passed profile name:

console.log(awsProfiles.getProfile()); // defaults to default!
// output format: { aws_access_key_id: 'xxxx', aws_secret_access_key: 'xxxx' }

Built With

  • AWS-SDK - AWS SDK for Nodejs and javascript

Authors

Alternatives:

If you'd prefer to not use this/a package you could instead do:

const SharedIniFile = require('aws-sdk/lib/shared_ini');
const sharedIniFile = new SharedIniFile();
const awsProfiles   = sharedIniFile.getProfiles();
console.log( awsProfiles );

This should work with the current version of the SDK and that's essentially how it's done in the package as well. I personally prefer to have this done using a separate package/module ( hence the reason I created it ).