#!/bin/sh
# Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.

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=/var/runtime/bootstrap
if [ -z "${AWS_LAMBDA_RUNTIME_API}" ]; then
  exec /usr/local/bin/aws-lambda-rie $RUNTIME_ENTRYPOINT
else
  export AUTH0_MANAGEMENT_CLIENT_SECRET=$(aws secretsmanager get-secret-value --secret-id ${AUTH0_MANAGEMENT_CLIENT_SECRET} | jq -r '.SecretString')
  export SENTRY_DSN=$(aws secretsmanager get-secret-value --secret-id ${SENTRY_DSN} | jq -r '.SecretString')
  exec $RUNTIME_ENTRYPOINT
fi
