Skip to content

Commit

Permalink
CLI: add support for SSO and --profile option (#1570)
Browse files Browse the repository at this point in the history
* match cdk sso changes and support --profile

* Add doc

Co-authored-by: Frank <wangfanjie@gmail.com>
  • Loading branch information
RichiCoder1 and fwang committed Mar 24, 2022
1 parent 04ea8cb commit 888213e
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 82 deletions.
30 changes: 18 additions & 12 deletions packages/cli/bin/scripts.js
Expand Up @@ -107,6 +107,10 @@ function addOptions(currentCmd) {
.option("role-arn", {
type: "string",
describe: "ARN of Role to use when invoking CloudFormation",
})
.option("profile", {
type: "string",
describe: "Use a specific profile from your credential file.",
});

if (currentCmd === cmd.deploy || currentCmd === cmd.remove) {
Expand Down Expand Up @@ -204,17 +208,19 @@ async function applyConfig(argv) {
return config;
}

async function loadAwsCredentials(script) {
async function loadAwsCredentials(script, argv) {
if (process.env.__TEST__ === "true") return;
if (![
cmd.diff,
cmd.build,
cmd.deploy,
cmd.remove,
cmd.start,
cmd.console,
cmd.cdk,
].includes(script)) {
if (
![
cmd.diff,
cmd.build,
cmd.deploy,
cmd.remove,
cmd.start,
cmd.console,
cmd.cdk,
].includes(script)
) {
return;
}

Expand All @@ -223,7 +229,7 @@ async function loadAwsCredentials(script) {
// the credentials from the environment variables will be used. So if
// MFA is configured for the AWS profile, SST will prompt for MFA, and
// CDK CLI won't prompt again.
const credentials = await getAwsCredentials();
const credentials = await getAwsCredentials({ profile: argv.profile });
process.env.AWS_ACCESS_KEY_ID = credentials.accessKeyId;
process.env.AWS_SECRET_ACCESS_KEY = credentials.secretAccessKey;
if (credentials.sessionToken) {
Expand Down Expand Up @@ -505,7 +511,7 @@ async function run() {

const config = await applyConfig(argv);

await loadAwsCredentials(script);
await loadAwsCredentials(script, argv);

// Track
Telemetry.trackCli(script);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Expand Up @@ -23,7 +23,7 @@
"async-retry": "^1.3.3",
"aws-cdk": "2.15.0",
"aws-cdk-lib": "2.15.0",
"aws-sdk": "^2.761.0",
"aws-sdk": "^2.1095.0",
"chalk": "^4.1.0",
"chokidar": "^3.5.2",
"ci-info": "^3.3.0",
Expand Down

0 comments on commit 888213e

Please sign in to comment.