-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-capture-function.sh
More file actions
45 lines (40 loc) · 1.53 KB
/
Copy pathdeploy-capture-function.sh
File metadata and controls
45 lines (40 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
# This script installs the dependencies for the Lambda for capturing and saving pictures function that will run on Greengrass,
# then, it packages the dependencies together with the Lambda function code and deploys it to AWS with AWS CloudFormation.
# It must be executed from the 'deployment' directory and receives two arguments: --bucket and --stack-name
# Usage: ./deploy-capture-function.sh --bucket <bucketname> --stack-name <stackname>
HELP="You must include --bucket (S3 bucket name) and --stack-name (CloudFormation stack name)"
for i in "$@"
do
case $i in
--bucket|-b|--bucket-name)
BUCKETNAME="${2}"
;;
--stack-name|-s|--stack)
STACKNAME="${1}"
;;
-h|--help)
echo ${HELP}
shift # past argument
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
shift
done
if [ -z "$BUCKETNAME" -o -z "$STACKNAME" ]; then
echo ${HELP}
else
# Package the Lambda function
if sam build -t capture-template.yaml; then
# Transform the SAM template to an AWS CloudFormation template
if sam package --s3-bucket "${BUCKETNAME}" --output-template-file packaged-template.yaml; then
# Deploy the CloudFormation template
sam deploy --template-file ./packaged-template.yaml --stack-name "${STACKNAME}" --capabilities CAPABILITY_NAMED_IAM;
# Remove the intermediate template
rm ./packaged-template.yaml;
fi
fi
fi