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

assume-role-js

v1.1.1

Published

Command line tool to assume AWS IAM role, running on node.js

Downloads

7

Readme

assume-role-js

A simple CLI tool to assume AWS IAM role, written in TypeScript.

This project aims at a drop-in replacement of the most common and basic use cases of https://github.com/uber/assume-role-cli, which has not been updated for years and people keep complaining about some critical issues (such as not usable on windows).

System requirements

  • Node.js v16
  • AWS CLI v2

Also, please make sure that you have used aws configure to set up the basic IAM user credentials as your default profile. See https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html#cli-configure-quickstart-config for more details.

Install

Run the command below to install:

npm install -g assume-role-js

Features

Run commands inline with assumed role

assume-role-js --role arn:aws:iam::123456789:role/developer aws s3 ls

This line will assume the arn:aws:iam::123456789:role/developer role and use it to run aws s3 ls, without polluting your CLI system environment variables.

Note: same feature exists on https://github.com/uber/assume-role-cli

Print out the system environment variables needed by AWS CLI to run as assumed-role

assume-role-js --role arn:aws:iam::123456789:role/developer

Without inline AWS command, it will just print the system environment variables.

Output example:

AWS_ACCESS_KEY_ID=xxxx
AWS_SECRET_ACCESS_KEY=xxxx
AWS_SESSION_TOKEN=xxxx

Note: same feature exists on https://github.com/uber/assume-role-cli

Cache credentials

You may need to run multiple commands with assumed role, and it is tedious to enter the MFA token code every time.

We got you covered by caching credentials and expiration time via AWS Named Profile without the need to re-assume role every time.

The profile name is automatically generated by the role arn.

For example, role arn arn:aws:iam::123456:role/developer will generate profile name as 123456-developer.

Note: same feature exists on https://github.com/uber/assume-role-cli

Autodetect and use MFA device

This feature requires the IAM user has iam:GetUser and iam:ListMFADevices permission.

Example policy to attach is:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "iam:GetUser",
        "iam:ListMFADevices"
      ],
      "Resource": "arn:aws:iam::<account-ID>:user/${aws:username}"
    }
  ]
}

See https://github.com/uber/assume-role-cli#getting-started for more details

Note: same feature exists on https://github.com/uber/assume-role-cli

Development

If you would like to make changes to this tool, simply clone the repo.

Install dependencies

yarn

Compile and bundle the runnable

yarn build

Hot link the runnable to system

npm link

Run development build

yarn start --role arn:aws:iam::123456789:role/developer

yarn start --role arn:aws:iam::123456789:role/developer aws s3 ls

Troubleshooting

Getting error of "cannot be loaded because running scripts is disabled on this system"

This might happen when trying to run the script under PowerShell due to the execution policy.

Solution:

powershell -ExecutionPolicy Bypass