Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skecskes/d7486bb2700cad2472978916a21e28d9 to your computer and use it in GitHub Desktop.
Save skecskes/d7486bb2700cad2472978916a21e28d9 to your computer and use it in GitHub Desktop.
#!/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
#!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