REPO_NAME="dev-$USER-fibcow"

AWS_ACCOUNT_ID=103233932089
AWS_REGION=us-east-1

ECR_BASE="$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com"
ECR_REPO_BASE="$ECR_BASE/$REPO_NAME"

if [ -z "$1" ]; then
    echo '$1 - must be set as current tag version'
    exit 1
fi

TAG="$1"

set -x
set -e

# run image as a container
ECR_TAG="$ECR_REPO_BASE:$TAG"
docker run \
    -p "9000:8080" \
    -d \
    $ECR_TAG

CONTAINER_ID=$(docker ps -f label=project=cache_test -q)

# make a request to the container
curl --request POST \
  --url http://localhost:9000/2015-03-31/functions/function/invocations \
  --header 'Content-Type: application/json' \
  --data '{
	"n": 6
}' | jq

# take a look at the logs
docker logs $CONTAINER_ID

# shut down container
docker kill $CONTAINER_ID
