Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Emily Barbour committed Aug 30, 2020
0 parents commit 4915cae
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## aws-interactive-switch-profile

Utilizes `aws configure list-profiles` to allow switching of profiles.

Once a profile is selected, `export AWS_PROFILE=<SELECTED_PROFILE>` is run


43 changes: 43 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env node

const util = require('util');
const exec = util.promisify(require('child_process').exec);
const prompts = require('prompts');
const shell = require('shelljs');

async function getProfiles() {
const { stdout: profiles } = await exec('aws configure list-profiles');
const profile_array = profiles
.trim()
.split(/\s+/)
.map(value => {
return { value }
});
return profile_array;
}

async function run() {
const choices = await getProfiles();
const { profile } = await prompts({
type: 'select',
name: 'profile',
message: 'Select an AWS profile to switch to',
choices,
});

await writeProfile(profile);
}

async function writeProfile(profile) {
if (!profile) {
return;
}

shell.sed('-i', /export AWS_PROFILE=".*"/, 'export AWS_PROFILE="' + profile + '"', '~/.zshrc')
}

function onError(e) {
console.error(e);
}

run().catch(onError);
140 changes: 140 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "aws-interactive-switch-profile",
"version": "1.0.0",
"description": "Switch between AWS profiles",
"author": "Emily Barbour",
"license": "MIT",
"engines": {
"node": ">=8.17.0"
},
"bin": {
"aws-interactive-switch-profile": "index.js"
},
"dependencies": {
"prompts": "^2.3.0",
"shelljs": "^0.8.4"
},
"publishConfig": {
"registry": "https://registry.npmjs.org/"
},
"repository": "git://github.com/notacoat/aws-interactive-switch-profile.git"
}

0 comments on commit 4915cae

Please sign in to comment.