#!/usr/bin/env bash
set -e

DIR="$(cd "$(dirname "$0")" && pwd)"
DEV_DIR=$DIR/../scripts/aws

"$DEV_DIR"/localstackStart

# uncomment to show localstack logs
# "$DEV_DIR"/localstackLogs &

"$DEV_DIR"/createQueues
"$DEV_DIR"/createLambda
"$DEV_DIR"/createLambdaQueueMapping

export AWS_DYNAMO_TABLE=local-songwhip-queue-table

"$DEV_DIR"/createDynamoTable

onExit() {
  # silence stdout to avoid messing with the terminal prompt
  "$DEV_DIR"/localstackStop &> /dev/null
}

# Trap allows us to run some teardown when the shell is closed.
# I'm still confused why this isn't necessary for the test/script/test
# script which seems to hang on jest until until jest exits or sigint
# and then continues the parent script.
trap onExit EXIT

vercel dev -l 6000
