Lesson 1.1: Using the AWS CLI for Development Workflows
Developers frequently interact with cloud resources while building, testing, and deploying applications. Many of these interactions involve repetitive tasks such as provisioning infrastructure, inspecting service configurations, uploading artifacts, or triggering deployments. Performing these operations manually through the AWS Management Console can slow development workflows and introduce configuration inconsistencies.
The AWS Command Line Interface (CLI) provides a programmatic way to interact with AWS services directly from a terminal. Instead of navigating through graphical interfaces, developers can execute commands that call AWS service APIs. This approach enables automation, scripting, and integration with development pipelines.
The AWS CLI acts as a thin wrapper around AWS service APIs. Each command corresponds to an API operation, meaning that any action available in the AWS console or SDKs can typically be executed through the CLI.
Why developers use the AWS CLI
From a development perspective, the CLI is valuable because it allows infrastructure operations to become part of the development workflow rather than a separate operational process.
One of the primary advantages is automation. Development tasks such as deploying Lambda functions, updating container services, or configuring storage resources often require multiple steps. CLI commands can be embedded into shell scripts, enabling these operations to run automatically during builds or deployments.
Another benefit is environment reproducibility. When commands are documented or scripted, development environments can be recreated consistently. This reduces the risk of configuration drift between development, staging, and production environments.
The CLI is also useful for debugging and diagnostics. Developers can inspect resource states, review configuration details, and query service metadata directly from the terminal. For example, inspecting the configuration of an EC2 instance or retrieving the configuration of a load balancer can be done in seconds using CLI commands.
Finally, the CLI integrates naturally with CI/CD pipelines. Tools such as GitHub Actions, Jenkins, and AWS CodeBuild frequently use AWS CLI commands to provision resources, update infrastructure, or deploy application artifacts.
Understanding AWS CLI command structure
AWS CLI commands follow a consistent structure that mirrors AWS service APIs.
The general syntax is:
aws [parameters]
Each component represents a specific part of the API request.
- aws invokes the CLI executable.
- service specifies the AWS service being accessed. Examples include ec2, s3, lambda, rds, and cloudformation.
- operation corresponds to the API action being performed. Operations typically use descriptive names such as describe-instances, create-bucket, or update-function-code.
- parameters provide additional configuration required by the operation.
For example, retrieving information about EC2 instances:
aws ec2 describe-instances
In this command:
- ec2 identifies the Amazon EC2 service
- describe-instances calls the API operation that retrieves instance metadata
The CLI sends a signed API request to AWS and returns the response in JSON format.
Understanding CLI output and JSON responses
Most AWS CLI commands return structured JSON output. This format allows developers to programmatically parse results and extract specific values.
For example:
aws ec2 describe-instances
The output includes details such as:
- Instance IDs
- Instance state
- Network interfaces
- Security groups
- Attached volumes
Because the output is JSON, it can be processed using tools such as jq, shell scripts, or programming languages that support JSON parsing.
Developers often combine CLI commands with filtering options to retrieve only the necessary fields.
Example:
aws ec2 describe-instances \
--query "Reservations[*].Instances[*].InstanceId"
This command filters the response to return only instance IDs.
Installing the AWS CLI
The AWS CLI is available for Linux, macOS, and Windows. It is distributed as a standalone package and can be installed using package managers or direct downloads.
For example, on macOS using Homebrew:
brew install awscli
On Linux using the official installer:
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
After installation, verify the installation:
aws --version
The output confirms the installed CLI version and underlying Python runtime.
Configuring authentication credentials
Before executing commands against AWS services, the CLI must be configured with credentials. These credentials allow the CLI to authenticate requests and sign API calls.
The simplest configuration method uses the interactive setup command:
aws configure
During configuration, the CLI prompts for:
- AWS Access Key ID
- AWS Secret Access Key
- Default region
- Default output format
These values are stored locally in configuration files.
Typical locations include:
~/.aws/credentials
~/.aws/config
The credentials file stores authentication keys, while the config file stores region and output preferences.
Developers working with multiple environments often configure multiple named profiles. This allows switching between accounts or roles without modifying credentials.
Example:
aws configure --profile dev
Commands can then reference the profile explicitly:
aws s3 ls --profile dev
Running basic AWS CLI commands
Once configured, developers can begin executing commands against AWS services.
For example, listing S3 buckets in the account:
aws s3 ls
Uploading a file to an S3 bucket:
aws s3 cp file.txt s3://my-bucket/
Describing EC2 instances:
aws ec2 describe-instances
Creating a new S3 bucket:
aws s3api create-bucket \
--bucket my-example-bucket \
--region us-east-1
Each command interacts with the corresponding AWS service API and returns a structured response.
Using the CLI in development workflows
In real-world development environments, the AWS CLI is rarely used in isolation. Instead, it becomes part of larger automation workflows.
For example, a typical deployment script for a serverless application may include steps such as:
- Packaging the application code
- Uploading build artifacts to an S3 bucket
- Updating a Lambda function
- Publishing a new version
- Updating an API Gateway deployment
Each step can be implemented using CLI commands executed sequentially in a shell script.
Because CLI commands are deterministic and scriptable, they help ensure that deployments remain consistent across environments.
CLI vs SDKs for developers
Developers often use both the AWS CLI and AWS SDKs, but for different purposes.
The AWS CLI is primarily used for:
- manual operations
- scripting infrastructure tasks
- debugging service configurations
- interacting with resources during development
In contrast, AWS SDKs are embedded within application code and are used to interact with AWS services programmatically at runtime.
For example, an application might use the AWS SDK to store files in S3, while a deployment pipeline uses the CLI to create the bucket and configure permissions.
The AWS CLI provides developers with a powerful interface for interacting with AWS services through commands executed from a terminal. By mapping directly to AWS service APIs, the CLI enables automation, scripting, and integration with development pipelines. Understanding how to structure commands, configure credentials, and integrate CLI operations into development workflows allows developers to manage cloud resources efficiently and consistently.
My name is Naeem ul Haq. I’ve been working with AWS since its early days and have deep expertise across its evolving ecosystem.