
AWS CLI Command Chaining
My secret sauce, using Q Chat to build changing commands
Stuart Clark
Amazon Employee
Published Mar 12, 2025
In the world of AWS management, efficiency is everything, constant context switching can slow everyone down. Based on research and industry surveys, developers typically lose between 30 to 45 minutes per day due to context switching. These costs are even higher for tasks requiring deep work and complex problem-solving, which are common in software development.
While many of us are familiar with basic Amazon Q capabilities, there's a particularly powerful feature that deserves some more attention: CLI command chaining. This I think is a real hidden gem, which allows you to create sophisticated command pipelines that would typically require custom scripts.
Let me show you how Amazon Q Developer CLI can transform complex AWS operations into elegant one-liners.
Managing AWS resources often requires multiple sequential operations. For example, you might need to, find specific EC2 instances based on tags, extract their IDs and use those IDs to perform additional operations, then format and filter the results. In the past for me this this meant me writing scripts or chaining commands manually. But with Q chat in the CLI I can generate these complex command chains, saving time and reducing errors. Let me show you this example of before and after.
Ok, let's say you want to identify EC2 instances with low CPU utilization over the past week to optimize costs. Normally I might write a script that calls the AWS CLI multiple times, processes the output, and generates a report.
But now in the CLI I can ask for a command chain that accomplishes this task.

Thats cool, now lets say I need to identify and fix security groups with overly permissive rules? We can do this.

These first two example are quite simple, but say we are managing multiple AWS accounts? We can generate commands that work across accounts using AWS Organizations.

Pretty cool right, let's look at some other examples. One use case which I came accross and thought was great was writting a cost optimization with automated snapshot cleanup. Here's how can Q Chat can help you identify and clean up old EBS snapshots to reduce storage costs.

This final example I want to close with show us how we can automated tagging compliance. this will ensure all our resources have required tags with this command chain

A few tips and trick I learnt myself when using this and getting the most out of the command line was these four items:
- Be specific about your goal**: "Create an AWS CLI command chain that finds all EBS volumes not attached to instances and outputs their IDs and sizes"
- Mention the tools you want to use**: "Using AWS CLI and jq, create a command to find EC2 instances with specific tags and restart them"
- Specify the format**: "Generate a bash one-liner that uses AWS CLI to create a CSV report of all S3 buckets and their total sizes"
- Ask for explanations**: "Can you explain how this AWS CLI command chain works and what each part does?"
This ability to generate sophisticated AWS CLI command chains is great for cloud administrators and developers. For me this bridges the gap between simple one-off commands and full script development, giving a powerful automation capabilities without leaving your command line. Next time you find yourself thinking "I should write a script for this AWS task," try asking Amazon Q Developer CLI to generate a command chain instead. You might be surprised at how much you can accomplish with a single prompt. Its easy to get set up
- (Optional) Verify the downloaded file for Amazon Q for command line on macOS. For more information, see Verifying your download.
- Authenticate with Builder ID, or with IAM Identity Center using the start URL given to you by your account administrator.
- Follow the instructions to install the shell integrations, and to grant macOS accessibility permissions.
What complex AWS operations would you like to simplify with command chaining? Let me know in the comments!
---
*Note: The commands in this blog post are examples and may need adjustments for your own specific environment and uses case. Always review and test commands before running them.*
*Note: The commands in this blog post are examples and may need adjustments for your own specific environment and uses case. Always review and test commands before running them.*
Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.