I’ll go over a useful way to summarize CloudFormation templates resources with jq. This is useful when you are looking at a CloudFormation template and trying to understand it. We’ll download an example CloudFormation template and use run through some useful jq commands summarize the resources defined in a CloudFormation template. Note, I’ll only show the output that is useful for understanding.

First, download a sample template. We’ll download a typical Auto Scaling template:

wget https://s3.amazonaws.com/cloudformation-templates-us-east-1/AutoScalingMultiAZWithNotifications.template
mv AutoScalingMultiAZWithNotifications.template autoscaling.json

Colorize the output with jq:

cat autoscaling.json | jq '.'

Summarize top-level sections:

$ cat autoscaling.json | jq 'keys[]'

Show the leaf paths of the template structure:

$ cat autoscaling.json | jq --compact-output '. | leaf_paths' | sed -e 's/,[0-9][0-9]*,/,1000,/g' | sed -e 's/,[0-9][0-9]*\]/,1000\]/g' | sort -u

Check out the Resources only:

$ cat autoscaling.json | jq '.Resources'
  "NotificationTopic": {
    "Type": "AWS::SNS::Topic",
    "Properties": {
      "Subscription": [
          "Endpoint": {
            "Ref": "OperatorEMail"
          "Protocol": "email"

This still a lot of information at this point. Also, notice that the structure of the Resources section has a key that varies. This is called the Logical Id. This structure makes it harder to go down and inspect it further. But jq has a useful to_entries command that we can use to restructure the format to make it easier to traverse.

cat autoscaling.json | jq '.Resources | to_entries'
    "key": "NotificationTopic",
    "value": {
      "Type": "AWS::SNS::Topic",
      "Properties": {
        "Subscription": [
            "Endpoint": {
              "Ref": "OperatorEMail"

The to_entries methods changed the structure so that there is a consistent key and value path for each resource in the structure now. We can now list the resources in the CloudFormation template.

$ cat autoscaling.json | jq '.Resources | to_entries | .[].value.Type'

Finally, I like to sort the output and count them so we get a nice summary:

$ cat autoscaling.json | jq -r '.Resources | to_entries | .[].value.Type' | sort | uniq -c | sort -r
   2 AWS::CloudWatch::Alarm
   2 AWS::AutoScaling::ScalingPolicy
   1 AWS::SNS::Topic
   1 AWS::ElasticLoadBalancingV2::TargetGroup
   1 AWS::ElasticLoadBalancingV2::LoadBalancer
   1 AWS::ElasticLoadBalancingV2::Listener
   1 AWS::EC2::SecurityGroup
   1 AWS::AutoScaling::LaunchConfiguration
   1 AWS::AutoScaling::AutoScalingGroup

Hope this helps! 🎉 This is also even shorter and sweeter with lono inspect summary.

Related Posts: