Skip to content

Commit a88edbe

Browse files
authored
Feat/execute script enhancements (#281)
* feat: Allowed execute script to work without cloudformation and enhanced it to allow an argument to point to a custom input file * feat: improved error handling * feat: update README-EXECUTE.md * feat: update README-EXECUTE.md * feat: remove script comment
1 parent cfc993a commit a88edbe

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

README-EXECUTE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Independently of how you've deployed the state machine, you can execute it in a
66

77
You'll find a few sample scripts in the `scripts` folder.
88

9-
Feel free to customize the `scripts/sample-execution-input.json`, and then run `scripts/execute.sh`.
9+
Feel free to customize the `scripts/sample-execution-input.json` or add a new json file, and then run `scripts/execute.sh [input json]` by default if input json is not passed then the script will default to `sample-execution-input.json`.
1010

1111
The script will start a state machine execution, wait for the execution to complete (polling), and then show the execution results.
1212

scripts/execute.sh

100644100755
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
#!/bin/bash
22
# config
3-
STACK_NAME=lambda-power-tuning
4-
INPUT=$(cat scripts/sample-execution-input.json) # or use a static string
3+
4+
set -euo pipefail
5+
6+
if [[ $# -gt 1 ]]
7+
then
8+
echo "Incorrect Usage: $0 [input json file path]"
9+
exit 1
10+
fi
11+
12+
STACK_NAME=lambda_power_tuning
13+
INPUT=$(cat "${1:-sample-execution-input.json}") # or use a static string
514

615
# retrieve state machine ARN
7-
STATE_MACHINE_ARN=$(aws cloudformation describe-stacks --stack-name $STACK_NAME --query 'Stacks[0].Outputs[?OutputKey==`StateMachineARN`].OutputValue' --output text)
16+
STATE_MACHINE_ARN=$(aws stepfunctions list-state-machines --query "stateMachines[?contains(name,\`${STACK_NAME}\`)]|[0].stateMachineArn" --output text | cat)
817

918
# start execution
1019
EXECUTION_ARN=$(aws stepfunctions start-execution --state-machine-arn $STATE_MACHINE_ARN --input "$INPUT" --query 'executionArn' --output text)
@@ -30,7 +39,7 @@ do
3039
echo $STATUS
3140
echo "Execution output: "
3241
# retrieve output
33-
aws stepfunctions describe-execution --execution-arn $EXECUTION_ARN --query 'output' --output text
42+
aws stepfunctions describe-execution --execution-arn $EXECUTION_ARN --query 'output' --output text | cat
3443
break
3544
fi
3645
done

0 commit comments

Comments
 (0)