forked from mstine/image-pipeline-aws-lambda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploySam.sh
executable file
·45 lines (34 loc) · 1.06 KB
/
deploySam.sh
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
#!/usr/bin/env bash
usage() {
echo "$0: usage: $0 <s3-bucket> <stack-name>"
echo "- s3-bucket: package output location for CloudFormation template"
echo "- stack-name: name for CloudFormation stack"
echo " All resources in stack will have stack-name as part of name."
}
test_aws() {
aws sts get-caller-identity >/dev/null
if [ $? -ne 0 ] ; then
exit $?
fi
}
do_npm_installs() {
for pkg in $(find . -maxdepth 2 -mindepth 2 -type f -name 'package.json' -exec dirname {} \;); do
pushd $pkg
npm install
popd
done
}
if [ $# -ne 2 ]; then
usage
exit 127
fi
S3_BUCKET=$1
STACK_NAME=$2
test_aws
do_npm_installs
aws s3 mb s3://${S3_BUCKET}
aws cloudformation package --template-file ./sam-template.yml --s3-bucket ${S3_BUCKET} --output-template-file packaged-sam-template.yml
aws cloudformation deploy --template-file ./packaged-sam-template.yml --stack-name ${STACK_NAME} --capabilities CAPABILITY_IAM
echo -e "To clean up stack resources and s3 bucket, run:\n"
echo "$(dirname $0)/cleanupSam.sh ${S3_BUCKET} ${STACK_NAME}"
exit 0