Skip to main content
This lesson explains how the AWS Command Line Interface (AWS CLI) fits into CloudFormation workflows. The AWS CLI lets you control AWS services programmatically from your local terminal (macOS, Linux, or Windows), enabling one-off operations, scripted automation, and CI/CD-driven provisioning without the AWS Management Console.
A slide titled "AWS CLI – Introduction" showing the AWS Command Line Interface icon controlling AWS services via a downward arrow and a "Using text command" label. A checklist on the right lists capabilities like running terminal commands to create resources, uploading to S3, launching servers, saving time, and enabling automation/scripting.
What the AWS CLI enables
  • Provision and manage infrastructure using scripts and CI/CD pipelines instead of manual clicks.
  • Upload and download objects to/from Amazon S3.
  • Launch and manage compute resources such as EC2 instances.
  • Automate CloudFormation stack lifecycle actions (create, update, delete, inspect).
Key capabilities and common use cases Prerequisites and configuration
  1. Install the AWS CLI (v2 recommended). See the official AWS CLI installation guide: https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html
  2. Ensure you have an AWS account and an IAM user or role with the necessary permissions for CloudFormation and the resources your templates create.
  3. Configure the CLI with your credentials and defaults:
The command prompts for:
  • AWS Access Key ID
  • AWS Secret Access Key
  • Default region name (for example, us-east-1)
  • Default output format (json, text, or table)
Ensure the AWS - IAM user or role whose credentials you use has the necessary permissions to perform CloudFormation and any resource-specific actions (for example, creating Amazon Elastic Compute Cloud (EC2) instances or Amazon Simple Storage Service (Amazon S3) buckets).
Workflow comparison: Console (manual) vs. AWS CLI (automated)
  • Manual (console)
    1. Author CloudFormation template (YAML/JSON).
    2. Open AWS Management Console → CloudFormation.
    3. Create a stack by uploading the template or providing a template URL.
    4. CloudFormation provisions resources and you monitor events in the console.
  • AWS CLI
    1. Author CloudFormation template (YAML/JSON).
    2. Run CLI commands to create, update, or delete stacks.
    3. CloudFormation provisions resources; CI/CD and scripts can automate end-to-end flows.
Using the CLI removes the manual console steps and is recommended for repeatable, auditable automation. Common AWS CLI commands for CloudFormation Create a new stack from a local template:
Create or update a stack idempotently (recommended for most workflows):
Create a stack using a template stored in S3:
Check stack status and events:
If your template creates or modifies IAM resources you must include an appropriate --capabilities flag such as CAPABILITY_IAM or CAPABILITY_NAMED_IAM. Omitting this will cause the stack operation to fail.
Practical tips and best practices
  • Prefer aws cloudformation deploy for CI/CD pipelines because it handles change sets and parameter handling more gracefully than create-stack.
  • Use S3 for large templates or bundled assets; reference them via --template-url.
  • Always grant the least-privilege IAM permissions required for the CLI user/role.
  • Use describe-stack-events and CloudFormation console events for troubleshooting failed operations.
  • Integrate CLI commands in pipeline steps (GitHub Actions, GitLab CI, Jenkins) to enable reproducible infrastructure changes.
Quick command reference Links and references This overview covers the essential ways to use the AWS CLI with CloudFormation for automated, scriptable infrastructure management.

Watch Video