#!/usr/bin/env bash

# desc:   	zips up lambda function resources and uploads to aws
# usage:  	./scripts/deploy.sh
# docs:   	http://docs.aws.amazon.com/cli/latest/reference/lambda/upload-function.html

zip -r function.zip package.json node_modules/* fkeychecks.sh index.js gawk

aws lambda update-function-code \
    --function-name pg-import \
    --zip-file fileb://function.zip

rm function.zip

#!/usr/bin/env bash

# desc:   Provisions AWS Resources (S3 Bucket), archives lambda function and assets and uploads to AWS Lambda
# usage:  bash ./scripts/deploy.sh
# docs:   http://docs.aws.amazon.com/cli/latest/reference/lambda/upload-function.html

BUCKET=tesera.svc.datapackage-validator

aws s3 mb "s3://$BUCKET"

# Add readme to explain what this bucket is used for
cat << EOF | aws s3 cp - "s3://$BUCKET/readme.txt" --content-type 'text/plain'
** AUTO GENERATED BY CI DEPLOYMENT SCRIPT (https://github.com/tesera/awslambda-datapackage-validator/blob/master/deploy.sh) **

bucket:         "${BUCKET}"
owner:          yves.richard@tesera.com
project:        https://github.com/tesera/datapackage-validator
description:    awslambda-datapackage-validator is an AWS Lambda function used for validating
                csv tabular datapackages (http://dataprotocols.org/tabular-data-package/index.html)
                against a JSON Table Schema (http://dataprotocols.org/json-table-schema/index.html)
                using bawlk (https://github.com/tesera/bawlk).
EOF

# archive function assets into a zip archive
zip -r function.zip package.json node_modules/* fkeychecks.sh index.js gawk

# todo: create function if not exist

# upload function to aws
aws lambda update-function-code \
    --function-name pg-import \
    --zip-file fileb://function.zip

# cleanup
rm function.zip

Update depoy script to provision required AWS resource
Update depoy script to provision required AWS resource
