diff --git a/package.json b/package.json index dc47611..8afbe28 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "samp-cli", - "version": "1.0.66", + "version": "1.0.67", "description": "CLI tool for extended productivity with AWS Serverless Application Model (SAM)", "main": "index.js", "scripts": { diff --git a/src/commands/stepfunctions/index.js b/src/commands/stepfunctions/index.js index 6631a47..5668523 100644 --- a/src/commands/stepfunctions/index.js +++ b/src/commands/stepfunctions/index.js @@ -15,6 +15,7 @@ program .option("--region [region]", "The AWS region to use. Falls back on AWS_REGION environment variable if not specified") .action(async (cmd, opts) => { + try { if (cmd === "init") { opts.logicalId = await inputUtil.text("Name of state machine resource", "StateMachine"); opts.aslFile = await inputUtil.text("Path to output ASL definition file", "statemachine.yaml"); @@ -27,5 +28,12 @@ program } else { console.log("Unknown command. Valid commands are: init, sync, test-state"); } + } catch (e) { + console.log("\n" + e.message + "\nTo see the full stack trace, set environment variable SAMP_DEBUG=1 and run the command again."); + if (process.env.SAMP_DEBUG) { + console.log(e.stack); + } + process.exit(1); + } return; }); diff --git a/src/commands/stepfunctions/test-state.js b/src/commands/stepfunctions/test-state.js index ae1cbbc..03e9a2b 100644 --- a/src/commands/stepfunctions/test-state.js +++ b/src/commands/stepfunctions/test-state.js @@ -12,9 +12,25 @@ const { Spinner } = require('cli-spinner'); const os = require('os'); let clientParams; -async function run(cmd) { +async function run(cmd) { const config = await samConfigParser.parse(); - const credentials = await fromSSO({ profile: cmd.profile || config.profile || 'default' }); + + if (!cmd.stackName && !config.stack_name) { + console.log("No stack name found. Use --stack-name or set stack_name in samconfig.toml"); + process.exit(1); + } + + if (!cmd.region && !config.region) { + console.log("No region found. Use --region or set region in samconfig.toml"); + process.exit(1); + } + + let credentials; + try { + credentials = await fromSSO({ profile: cmd.profile || config.profile || 'default' }); + } catch (e) { + } + clientParams = { credentials, region: cmd.region || config.region } const sfnClient = new SFNClient(clientParams); const cloudFormation = new CloudFormationClient(clientParams); diff --git a/src/shared/samConfigParser.js b/src/shared/samConfigParser.js index e1fa405..d6290fb 100644 --- a/src/shared/samConfigParser.js +++ b/src/shared/samConfigParser.js @@ -24,9 +24,9 @@ function parse() { const envConfig = config[configEnv].deploy.parameters; envConfig.configEnv = process.env.configEnv || 'default'; - envConfig.stack_name = envConfig.stack_name || config[configEnv].global.parameters.stack_name - envConfig.region = envConfig.region || config[configEnv].global.parameters.region || process.env.AWS_REGION; - envConfig.profile = envConfig.profile || config[configEnv].global?.parameters.profile || process.env.AWS_PROFILE || 'default'; + envConfig.stack_name = envConfig.stack_name || config[configEnv].global?.parameters?.stack_name + envConfig.region = envConfig.region || config[configEnv].global?.parameters?.region || process.env.AWS_REGION; + envConfig.profile = envConfig.profile || config[configEnv].global?.parameters?.profile || process.env.AWS_PROFILE || 'default'; return envConfig; }