#!/bin/sh
set -e

FUNCTION_NAME=$1

if [ -z "$FUNCTION_NAME" ]; then
  echo "argument FUNCTION_NAME missing"
  exit 1
fi

yarn esbuild ./lambda/index.js \
  --bundle \
  --platform=node \
  --target=node18 \
  --outdir=./lambda/.dist

cd lambda/.dist
zip lambda.zip index.js
cd -

# use raw aws-cli as we don't need this when using localstack,
# it's useful to update staging/production lambda code in
# conjuction with awsume (see README.md).
aws lambda update-function-code \
  --function-name "$FUNCTION_NAME" \
  --zip-file fileb://lambda/.dist/lambda.zip

