forked from matsev/cloudformation-api-gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy-stack.sh
executable file
·36 lines (28 loc) · 1.1 KB
/
deploy-stack.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
#!/usr/bin/env bash
aws --version >/dev/null 2>&1 || { echo >&2 "I require AWS Cli but it's not installed. ¯\_(ツ)_/¯ Aborting."; exit 1; }
# Deploy the stack (create and/or update) in a single file
set -e
if [ -z "$AWS_DEFAULT_REGION" ]; then
aws_region="eu-west-1"
else
aws_region=$AWS_DEFAULT_REGION
fi
preffix="greeting"
stack_name=$preffix'-stack'
script_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
template_base="$script_dir/../cloudformation.template"
template_compiled="$script_dir/../packaged.yaml"
deploy_bucket=$aws_region'-'$( aws sts get-caller-identity --query Account --output text )'-code'
if aws s3api head-bucket --bucket $deploy_bucket 2>/dev/null; then
aws s3api create-bucket --bucket $deploy_bucket --region $aws_region
fi
aws cloudformation package \
--template-file $template_base \
--output-template-file $template_compiled \
--s3-bucket $deploy_bucket \
--s3-prefix $preffix
aws cloudformation create-stack \
--stack-name $stack_name \
--template-body fileb://"$template_compiled" \
--capabilities CAPABILITY_IAM \
--region $aws_region