#!/bin/bash
qa=-qa

# validate that there is build dir:
ls
ls ~
if [ -f ~/lambda.zip ]; then
    aws s3 rm --recursive --exclude "*" --include "$SVC_NAME.zip" s3://p81-$ENV_NAME-env-files${qa}/zips/
    if $BUILD_FROM_SCRATCH ; then
        aws s3 cp ~/lambda.zip s3://p81-$ENV_NAME-env-files${qa}/zips/$SVC_NAME.zip
        aws lambda update-function-code --function-name $LAMBDA_NAME  --s3-bucket p81-$ENV_NAME-env-files${qa} --s3-key zips/$SVC_NAME.zip --region $LAMBDA_REGION
    else
        aws s3 cp ~/lambda.zip s3://p81-$ENV_NAME-env-files${qa}/zips/$SVC_NAME-$VERSION_TO_DEPLOY.zip
        aws lambda update-function-code --function-name $LAMBDA_NAME  --s3-bucket p81-$ENV_NAME-env-files${qa} --s3-key zips/$SVC_NAME-$VERSION_TO_DEPLOY.zip --region $LAMBDA_REGION
    fi
else
	echo "could not download the desired version from nexus or did not build the build dir"
    exit 1
fi