1 min read

CloudFormation Stack Resources Summary

We were having a discussion over on the Serverless Forum about CloudFormation resources, and I came up with this AWS CLI command that I could see myself using later, so I'm going to put it here so I don't forget.

The Serverless Framework is great because it makes provisioning a server-less application so easy. The flip-side is that it does a lot in the background to make it all just work, so this snippet gives you a bit more insight in to what it's doing "under the hood".

The following command will print an ordered list of all the resources and a count of how many are in your stack:

aws cloudformation describe-stack-resources \
  --stack-name [YourStackName] \
  --query "StackResources[].ResourceType" \
  --output text \
  | tr "\t" "\n" \
  | sort \
  | uniq -c \
  | sort -nr

Here's what it looks like for the Serverless Slack Bot I'm building:

   4 AWS::Lambda::Version
   4 AWS::Lambda::Function
   4 AWS::ApiGateway::Method
   3 AWS::Lambda::Permission
   3 AWS::ApiGateway::Resource
   1 AWS::S3::Bucket
   1 AWS::IAM::Role
   1 AWS::IAM::Policy
   1 AWS::DynamoDB::Table
   1 AWS::ApiGateway::RestApi
   1 AWS::ApiGateway::Deployment

Update: Ryan Scott Brown (of Serverless Code) was kind enough to point out an improvement to the sort command so that it handles stacks with > 9 of any resource type.