forked from jpsim/AWSPics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy
executable file
·45 lines (38 loc) · 1.26 KB
/
deploy
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 -e
if [ -z "$1" ]; then
echo "Usage:"
echo " deploy my.bucket.name"
echo "The bucket will be used to store the Lambda code when deploying."
echo "It will be created if needed"
exit 1
else
s3Bucket=$1
fi
output_template_file=$(mktemp)
stackName="AWSPics"
for function in login resize site-builder; do
(
cd $function
docker build -t "cloudformation-lambda-$function" .
docker run "cloudformation-lambda-$function" > ../dist/lambda-$function.zip
)
done
# create the target S3 bucket if needed
if ! aws s3 ls "s3://${s3Bucket}" > /dev/null
then
aws s3 mb "s3://${s3Bucket}"
fi
# create and upload the CloudFormation package
aws cloudformation package \
--template-file app.yml \
--output-template-file "${output_template_file}" \
--s3-bucket "${s3Bucket}"
# deploy it
aws cloudformation deploy \
--template-file "${output_template_file}" \
--stack-name ${stackName} \
--capabilities CAPABILITY_IAM \
--parameter-overrides file://dist/config.json || true
# Invoke SiteBuilder function
funcName="$(aws cloudformation describe-stack-resource --stack-name ${stackName} --logical-resource-id SiteBuilderFunction | sed -n 's/.*"PhysicalResourceId": "\(.*\)",/\1/p')"
aws lambda invoke --function-name ${funcName} "$(mktemp)"