Supply Chain

Query CloudFormation Templates

Query AWS CloudFormation and SAM templates with cnquery

Rely on cnquery to query and analyze AWS CloudFormation templates and AWS SAM (Serverless Application Model) templates. Explore resources, parameters, outputs, and mappings within your infrastructure-as-code configurations.

Requirements

To analyze CloudFormation templates with cnquery, you must have:

Query a CloudFormation template

To open a cnquery shell and query a CloudFormation template:

cnquery shell cloudformation PATH
For...Substitute...
PATHThe path to the CloudFormation template file

For example:

cnquery shell cloudformation ./templates/infrastructure.yaml

Or to query a SAM template:

cnquery shell cloudformation ./sam/template.yaml

Example queries

Once connected, you can query CloudFormation template resources.

This query retrieves all resources defined in the template:

cnquery> cloudformation.template.resources
cloudformation.template.resources: [
  0: cloudformation.resource type="AWS::EC2::Instance"
  1: cloudformation.resource type="AWS::S3::Bucket"
  ...
]

This query retrieves all parameters:

cnquery> cloudformation.template.parameters
cloudformation.template.parameters: [
  0: cloudformation.parameter name="InstanceType"
  1: cloudformation.parameter name="Environment"
  ...
]

This query retrieves outputs:

cnquery> cloudformation.template.outputs
cloudformation.template.outputs: [
  0: cloudformation.output name="InstanceId"
  ...
]

This query retrieves mappings:

cnquery> cloudformation.template.mappings
cloudformation.template.mappings: {
  ...
}

Exit the cnquery shell

To exit the cnquery shell, either press Ctrl + D or type exit.

Learn more

On this page