@campus-explorer/aws-credentials
TypeScript icon, indicating that this package has built-in type declarations

6.0.0 • Public • Published

@campus-explorer/aws-credentials

JavaScript helper code to manage AWS credentials

Install

yarn add @campus-explorer/aws-credentials

Usage

import AWS from 'aws-sdk';
import {
    getProfileCredentials,
    useProfile,
    getProfileConfig,
} from '@campus-explorer/aws-credentials';

# Get an AWS.Credentials object for the profile
const credentials = await getProfileCredentials('my-profile');

# Alternatively, set AWS to use the profile
await useProfile('my-profile', AWS.config);

# See if a profile exists
try {
    getProfileConfig('my-profile');
} catch (error) {
    // doesn't exist
}

Description

This package is similar to AWS.SharedIniFileCredentials, in that it loads credentials using the shared credentials file. However, it adds a few features:

  • integration with the AWS CLI cache
  • longer durations

Session Durations

By default, we will cache profiles that end in '-admin' for 1 hour, and all other profiles for 8 hours.

Functions

getProfileCredentials()

Returns an AWS.Credentials object.

getProfileCredentials(
    profile,
    { // optional options
        cacheDir, // optional, defaults to ~/.aws/cli/cache
        duration, // optional, defaults to duration rules noted above,
        getMfaToken, // optional, defaults to using inquirer
    },
})

useProfile()

Loads the profile's credential into the environment and the global credentials settings for the AWS SDK. You need to pass your copy of the AWS object.

useProfile({
    profile,
    AWS,
    {
        /* ... same options as getProfileCredentials() */
    }
})

Readme

Keywords

none

Package Sidebar

Install

npm i @campus-explorer/aws-credentials

Weekly Downloads

1

Version

6.0.0

License

MIT

Unpacked Size

17.4 kB

Total Files

20

Last publish

Collaborators

  • archer-eric
  • isharcher
  • archer-ci-cd
  • scaldwell77
  • archeredu
  • jbc99
  • mechanicmo
  • twong-archer