#!/bin/sh

if [ $# -ne 1 ]; then
  echo "entrypoint requires the handler name to be the first argument" 1>&2
  exit 142
fi
export _HANDLER="$1"

RUNTIME_ENTRYPOINT="/usr/local/bin/python3 -m awslambdaric ${_HANDLER}"
if [ -z "${AWS_LAMBDA_RUNTIME_API}" ]; then
  exec /usr/local/bin/aws-lambda-rie ${RUNTIME_ENTRYPOINT}
else
  export SLACK_TOKEN=$(aws secretsmanager get-secret-value --secret-id ${SLACK_TOKEN_ARN} | jq -r '.SecretString')
  exec ${RUNTIME_ENTRYPOINT}
fi
