-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildspec.yml
52 lines (48 loc) · 1.9 KB
/
buildspec.yml
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
version: 0.2
phases:
install:
runtime-versions:
python: 3.11
pre_build:
commands:
- env
- aws --version
- aws sts get-caller-identity
- pip install --quiet --upgrade pip
- pip install --quiet --upgrade cfn-lint
- cfn-lint --version
build:
commands:
- |
set -eux
PACKAGED_DIR="/tmp/packaged"
rm -rf "$PACKAGED_DIR"
mkdir -p "$PACKAGED_DIR"
TEMPLATES="$(find ./stacks -type f)"
echo "Found CloudFormation templates: $TEMPLATES"
echo "Running cfn-lint"
# cfn-lint rules: https://github.com/aws-cloudformation/cfn-lint/blob/main/docs/rules.md
cfn-lint -I $TEMPLATES --ignore-checks W3002
for TEMPLATE in $TEMPLATES; do
FILENAME="$(basename "$TEMPLATE")"
STACK_NAME="${FILENAME%.*}"
echo "Packaging template '$TEMPLATE'"
aws cloudformation package --template-file "$TEMPLATE" --s3-bucket "$S3_BUCKET_ARTIFACTS" --output-template-file "${PACKAGED_DIR}/${FILENAME}"
echo "Deploying template '${PACKAGED_DIR}/${FILENAME}' as stack '$STACK_NAME'"
aws cloudformation deploy --template-file "${PACKAGED_DIR}/${FILENAME}" --stack-name "$STACK_NAME" --capabilities CAPABILITY_NAMED_IAM --no-fail-on-empty-changeset
done
post_build:
commands:
- |
for TEMPLATE in $TEMPLATES; do
STACKNAME=teststack
RESPONSE="$(aws cloudformation describe-stacks --stack-name "$STACKNAME")"
if [[ $RESPONSE =~ "$STACKNAME" ]]; then
echo "Stack "$STACKNAME" found"
else
echo "stack "$STACKNAME" not found"
fi
if [[ $RESPONSE =~ "REVIEW_IN_PROGRESS" ]]; then
echo "Stack "$STACKNAME" not executed"
fi
done