CloudFormationの差分がTruncated-Signatureで見れなくて、何年も人の手が入っていないymlだったので、とにかく差分が見たくて調べた時のメモ

まずは現状把握

current-template.jsonに現在の構成が出力されます

1
2
3
4
5
aws cloudformation get-template \
--stack-name <スタック名> \
--template-stage Original \
--query 'TemplateBody' \
--output json > current-template.json

ここから先は、人によるのかもしれませんが、中身は…こんな感じの1行で書かれたテキスト

1
"AWSTemplateFormatVersion: \"2010-09-09\"\nDescription: CloudFront For Product Service\n\n# This Template uses imports from the following stacks, some references are hard-coded to reduce the number of parameters\n# Product Static Content Stack (hard-coded Product-Static)\n#   - log and content s3\n# Security Header Lambda Stack (hard-coded Lambda-SecHeaders in us-east-1)\n#   - edge lambda\n# Product Dynamic Content (parameter)\n#   - alb target\n#   - the version is also imported, but not as a hard dependancy, this way you can update the app stack with a new version\n# SSL Certificate (based on Stage parameter)\n#   - ssl cert and domain info\n# \n#\n# While hard-coding the stack names reduces re-use, it also reduced the chance of error during deploy.\n# Since the cache behavior is project specific, you will need to copy file anyway, so a simple search and replace for hard-coded values can be done.\n#\n\nParameters:\n    Stage:\n        Description: The Stage this stack controls\n        Type: String\n        AllowedValues:\n            - Testing\n            - Staging\n            - Production\n    AppStack:\n

jqで変換します。 decorded-template.jsonが出力されます

1
jq -r '.' current-template.json > decoded-template.yaml

整形され、読みやすくなりました

1
head decoded-template.yaml
1
2
3
4
5
6
7
8
9
10
AWSTemplateFormatVersion: "2010-09-09"
Description: CloudFront For Product Service

# This Template uses imports from the following stacks, some references are hard-coded to reduce the number of parameters
# Product Static Content Stack (hard-coded Product-Static)
# - log and content s3
# Security Header Lambda Stack (hard-coded Lambda-SecHeaders in us-east-1)
# - edge lambda
# Product Dynamic Content (parameter)
# - alb target

更新しようとしているテンプレートとの差分を取る

整形した現状構成のcloudfront.ymlと、リポジトリのdecoded-template.ymlの差分を取ります

1
diff cloudfront.yml decoded-template.yaml
1
2
-    WebACLId:
- Ref: "MyWebACL"

今回は、CloudfrontへWAFをアソシエーションする内容の差分だったので、期待通りの差分になりました