Last active
January 22, 2023 14:25
-
-
Save MatteoGioioso/fca0dec7b04b38bfd9428325bf549b14 to your computer and use it in GitHub Desktop.
AWS step functions local script: https://blog.hirvitek.com/post/how-to-test-aws-step-functions-locally_ciSl6E33Rfsd8pXQkc6KD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
CONTAINER_NAME=stepfunctions | |
STATE_MACHINE_DEFINITION=/path/to/yourstatemachine.json | |
STATE_MACHINE_NAME="Name of your process" | |
ENV_FILE=path/to/your-stepfunctions-local-credentials.txt | |
INPUT="{ \"myInput\": \"hello world\"}" | |
function get_value_from_json(){ | |
VALUE="$(jq .$1 temporary.json)" | |
VALUE="${VALUE%\"}" | |
VALUE="${VALUE#\"}" | |
rm temporary.json | |
echo $VALUE | |
} | |
echo 'Starting containers...' | |
docker container stop $CONTAINER_NAME | |
docker rm $CONTAINER_NAME | |
docker run -d --name $CONTAINER_NAME --network host -p 8083:8083 \ | |
--env-file $ENV_FILE \ | |
amazon/aws-stepfunctions-local | |
#Create a state machine. Temporary save the output into a json file | |
echo 'Creating state machine...' | |
aws stepfunctions \ | |
--endpoint http://localhost:8083 \ | |
create-state-machine --definition "`cat $STATE_MACHINE_DEFINITION`" \ | |
--name $STATE_MACHINE_NAME \ | |
--role-arn "arn:aws:iam::012345678901:role/DummyRole" \ | |
> temporary.json | |
STATE_MACHINE_ARN=$(get_value_from_json "stateMachineArn") | |
#Start the state machine | |
echo 'Starting state machine...' | |
aws stepfunctions \ | |
--endpoint http://localhost:8083 \ | |
start-execution \ | |
--state-machine $STATE_MACHINE_ARN \ | |
--input "$INPUT" \ | |
> temporary.json | |
EXECUTION_ARN=$(get_value_from_json "executionArn") | |
#Describe state machine execution | |
aws stepfunctions \ | |
--endpoint http://localhost:8083 \ | |
describe-execution \ | |
--execution-arn $EXECUTION_ARN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!bin/bash | |
# ./serve-sam-local.bash | |
TYPE=${1:-lambda} | |
NETWORK_NAME=lambda-local | |
CONTAINER_NAME=dynamodb | |
function set_env_variables(){ | |
set -a # automatically export all variables | |
source test.env | |
set +a | |
} | |
function cleanup(){ | |
echo "Cleaning up..." | |
docker container stop $CONTAINER_NAME | |
docker rm $CONTAINER_NAME | |
docker network rm $NETWORK_NAME | |
} | |
docker network create $NETWORK_NAME | |
docker run -d --name $CONTAINER_NAME --network $NETWORK_NAME -p 8000:8000 amazon/dynamodb-local | |
set_env_variables | |
sam local start-${TYPE} --docker-network $NETWORK_NAME | |
trap cleanup EXIT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment