-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathdeploy
executable file
·67 lines (57 loc) · 1.63 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash -e
DEFAULT_STACK_NAME="AWSPics"
stack_name="${DEFAULT_STACK_NAME}"
USAGE=$(cat <<-END
Usage:
deploy my.bucket.name
The bucket will be used to store the Lambda code when deploying.
It will be created if needed.
Optional usage:
deploy --stack-name=mystackname my.bucket.name
Specify stack name, otherwise it defaults to ${DEFAULT_STACK_NAME}
END
)
while [ $# -gt 1 ]; do
case "$1" in
--stack-name=*)
stack_name="${1#*=}"
;;
*)
echo "${USAGE}"
exit 1
esac
shift
done
if [ -z "$1" ]; then
echo "${USAGE}"
exit 1
else
s3_bucket=$1
fi
output_template_file=$(mktemp)
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://${s3_bucket}" > /dev/null
then
aws s3 mb "s3://${s3_bucket}"
fi
# create and upload the CloudFormation package
aws cloudformation package \
--template-file app.yml \
--output-template-file "${output_template_file}" \
--s3-bucket "${s3_bucket}"
# deploy it
aws cloudformation deploy \
--template-file "${output_template_file}" \
--stack-name ${stack_name} \
--capabilities CAPABILITY_IAM \
--parameter-overrides file://dist/config.json || true
# Invoke SiteBuilder function
func_name="$(aws cloudformation describe-stack-resource --stack-name ${stack_name} --logical-resource-id SiteBuilderFunction | sed -n 's/.*"PhysicalResourceId": "\(.*\)",/\1/p')"
aws lambda invoke --function-name ${func_name} --invocation-type Event "$(mktemp)"