Skip to content

Commit 64c5797

Browse files
committed
sample template script
1 parent 4f313b9 commit 64c5797

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

templates/create-stack.sh

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
if [[ $# -gt 1 ]]; then
4+
TEMPLATE_NAME=$1
5+
shift
6+
OVERRIDES="$@"
7+
OVERRIDES_ARG="--parameter-overrides ${OVERRIDES}"
8+
TEMPLATE=$(cat ${TEMPLATE_NAME}.yml)
9+
elif [[ $# -eq 1 ]]; then
10+
TEMPLATE_NAME=$1
11+
TEMPLATE=$(cat ${TEMPLATE_NAME}.yml)
12+
if [[ "$TEMPLATE" =~ PLACEHOLDER ]]; then
13+
echo "Usage: ./create-stack.sh <template-name> <parameters>"
14+
echo "e.g. ./create-stack.sh my-template parameter=value parameter2=value2"
15+
exit 0
16+
fi
17+
else
18+
echo "Usage: ./create-stack.sh <template-name> <parameters>"
19+
echo "e.g. ./create-stack.sh function-inline"
20+
echo "e.g. ./create-stack.sh my-template parameter=value parameter2=value2"
21+
exit 0
22+
fi
23+
STACK_NAME=lambda-${TEMPLATE_NAME}
24+
if [[ "$TEMPLATE" =~ "AWS::IAM::Role" ]]; then
25+
CAPA_ARG="--capabilities CAPABILITY_NAMED_IAM"
26+
fi
27+
aws cloudformation deploy --template-file ${TEMPLATE_NAME}.yml --stack-name ${STACK_NAME} ${CAPA_ARG} ${OVERRIDES_ARG}

templates/delete-stack.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
if [[ $# -eq 1 ]]; then
4+
TEMPLATE_NAME=$1
5+
else
6+
echo "Usage: ./delete-stack.sh <template-name>"
7+
echo "e.g. ./delete-stack.sh function-inline"
8+
exit 0
9+
fi
10+
STACK_NAME=lambda-${TEMPLATE_NAME}
11+
while true; do
12+
read -p "Delete stack ${STACK_NAME}? (y/n)" response
13+
case $response in
14+
[Yy]* ) aws cloudformation delete-stack --stack-name ${STACK_NAME}; break;;
15+
[Nn]* ) break;;
16+
* ) echo "Response must start with y or n.";;
17+
esac
18+
done

templates/function-inline.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Resources:
2929
Handler: index.handler
3030
MemorySize: 128
3131
Role: !GetAtt executionRole.Arn
32-
Runtime: nodejs12.x
32+
Runtime: nodejs16.x
3333
Timeout: 10
3434
TracingConfig:
3535
Mode: Active

0 commit comments

Comments
 (0)