Devops

Top Azure and AWS CLI Commands For Managing Resources

Description of the image

Amazon Web Services and Microsoft Azure have a CLI tool that developers can use to access as well as manage their various cloud services and solutions. 

Download AWS CLI: https://awscli.amazonaws.com/AWSCLIV2.msi

Download AZURE CLI: https://learn.microsoft.com/en-us/cli/azure/install-azure-cli

For Complete Walkthrough: https://devopsden.io/article/how-to-install-aws-cli

Prerequisites for AWS and Azure CLI

PrerequisiteAWS CLIAzure CLI
AccountAWS accountAzure account
Access Keys/SubscriptionAWS Access KeysAzure subscription
Operating SystemWindows, macOS, LinuxWindows, macOS, Linux
PythonRequired for AWS CLI v1 (Python 2.6.5+ or 3.3+)Optional (bundled Python version available)
InstallationPackage managers (pip, Homebrew), direct downloadPackage managers (pip, Homebrew), installation scripts
PermissionsNecessary IAM permissionsNecessary account permissions

Useful Azure CLI Commands

Manage Resource Groups and Template Deployments

CommandDescription
az group create
Create a new resource group.
az group delete
Delete a resource group.
az group deployment
Manage Azure Resource Manager deployments.
az group deployment cancel
Cancel a currently running template deployment.
az group deployment create
Start a deployment.
az group deployment delete
Delete a deployment.

Authentication

CommandDescription
az login
Log in to Azure.
az logout
Log out of Azure.

Account Management

CommandDescription
az account show
Display the details of the current subscription.

Virtual Machines

CommandDescription
az vm create
Create a new virtual machine.
az vm delete
Delete a virtual machine.
az vm start
Start a stopped virtual machine.
az vm stop
Stop a running virtual machine.
az vm list
List all virtual machines in a subscription.
az vm show
Show details of a specific virtual machine.

Storage Accounts

CommandDescription
az storage account create
Create a new storage account.
az storage account delete
Delete a storage account.
az storage account list
List all storage accounts in a subscription.

Networking

CommandDescription
az network vnet create
Create a virtual network.
az network vnet delete
Delete a virtual network.
az network vnet list
List virtual networks.
az network nsg create
Create a network security group.
az network nsg delete
Delete a network security group.
az network nsg list
List network security groups.

Azure Kubernetes Service (AKS)

CommandDescription
az aks create
Create a new Azure Kubernetes Service (AKS) cluster.
az aks delete
Delete an Azure Kubernetes Service (AKS) cluster.
az aks list
List Azure Kubernetes Service (AKS) clusters.
az aks get-credentials
Get access credentials for an AKS cluster.

Azure SQL Database

CommandDescription
az sql server create
Create a new SQL server.
az sql server delete
Delete a SQL server.
az sql server list
List SQL servers.
az sql db create
Create a new SQL database.
az sql db delete
Delete a SQL database.
az sql db list
List SQL databases.

Azure App Services

CommandDescription
az webapp create
Create a new web app.
az webapp delete
Delete a web app.
az webapp list
List web apps.
az webapp start
Start a web app.
az webapp stop
Stop a web app.

Monitoring and Management

CommandDescription
az monitor metrics list
List the metric values for a resource.
az monitor alert create
Create a new alert rule.
az monitor alert delete
Delete an alert rule.

Useful AWS CLI Commands

Authentication

CommandDescription
aws configure
Configure AWS CLI with your credentials and settings.
aws sts get-caller-identity
Get details about the IAM user or role whose credentials are used to call the API.

Account Management

CommandDescription
aws iam list-users
List all IAM users in the account.
aws iam create-user
Create a new IAM user.
aws iam delete-user
Delete an IAM user.

S3 (Simple Storage Service)

CommandDescription
aws s3 ls
List all S3 buckets.
aws s3 mb s3://<bucket-name>
Create a new S3 bucket.
aws s3 rb s3://<bucket-name>
Delete an S3 bucket.
aws s3 cp <source> <destination>
Copy files to and from S3 buckets.
aws s3 sync <source> <destination>
Sync files and directories to and from S3 buckets.

EC2 (Elastic Compute Cloud)

CommandDescription
aws ec2 describe-instances
List all EC2 instances.
aws ec2 start-instances --instance-ids <instance-id>
Start an EC2 instance.
aws ec2 stop-instances --instance-ids <instance-id>
Stop an EC2 instance.
aws ec2 terminate-instances --instance-ids <instance-id>
Terminate an EC2 instance.
aws ec2 create-key-pair --key-name <key-name>
Create a new key pair.

RDS (Relational Database Service)

CommandDescription
aws rds describe-db-instances
List all RDS instances.
aws rds create-db-instance
Create a new RDS instance.
aws rds delete-db-instance --db-instance-identifier <db-instance-id>
Delete an RDS instance.
aws rds start-db-instance --db-instance-identifier <db-instance-id>
Start an RDS instance.
aws rds stop-db-instance --db-instance-identifier <db-instance-id>
Stop an RDS instance.

IAM (Identity and Access Management)

CommandDescription
aws iam list-users
List all IAM users.
aws iam create-user --user-name <user-name>
Create a new IAM user.
aws iam delete-user --user-name <user-name>
Delete an IAM user.
aws iam list-roles
List all IAM roles.
aws iam create-role
Create a new IAM role.
aws iam delete-role --role-name <role-name>
Delete an IAM role.

Lambda

CommandDescription
aws lambda list-functions
List all Lambda functions.
aws lambda create-function
Create a new Lambda function.
aws lambda delete-function --function-name <function-name>
Delete a Lambda function.

CloudFormation

CommandDescription
aws cloudformation create-stack --stack-name <stack-name> --template-body <template-body>
Create a new stack.
aws cloudformation delete-stack --stack-name <stack-name>
Delete a stack.
aws cloudformation describe-stacks
List all stacks.

SQS (Simple Queue Service)

CommandDescription
aws sqs create-queue --queue-name <queue-name>
Create a new SQS queue.
aws sqs delete-queue --queue-url <queue-url>
Delete an SQS queue.
aws sqs list-queues
List all SQS queues.

SNS (Simple Notification Service)

CommandDescription
aws sns create-topic --name <topic-name>
Create a new SNS topic.
aws sns delete-topic --topic-arn <topic-arn>
Delete an SNS topic.
aws sns list-topics
List all SNS topics.

CloudWatch

CommandDescription
aws cloudwatch list-metrics
List CloudWatch metrics.
aws cloudwatch put-metric-alarm
Create or update an alarm and associate it with the specified metric.
aws cloudwatch delete-alarms --alarm-names <alarm-names>
Delete specified alarms.

Automate common tasks using Azure and AWS CLI commands

TaskAzure CLIAWS CLI
Create VMazure vm create --resource-group myResourceGroup --name myVM --image UbuntuLTS --admin-username azureuseraws ec2 run-instances --image-id ami-0abcdef1234567890 --count 1 --instance-type t2.micro --key-name MyKeyPair
List Resourcesazure resource list --resource-group myResourceGroupaws resourcegroupstaggingapi get-resources
Upload to Storageazure storage blob upload --container-name mycontainer --file myfile.txt --name myfile.txtaws s3 cp myfile.txt s3://mybucket/myfile.txt
Monitor Logsazure monitor activity-log list --resource-group myResourceGroupaws logs filter-log-events --log-group-name my-log-group
Delete Resourceazure resource delete --resource-group myResourceGroup --name myResourceaws ec2 terminate-instances --instance-ids i-1234567890abcdef0

Sample Scripts

Azure Script to Create and List VMs:

#!/bin/bash
# Create a VM
az vm create \
  --resource-group myResourceGroup \
  --name myVM \
  --image UbuntuLTS \
  --admin-username azureuser

# List all VMs
az vm list --output table

AWS Script to Create and List EC2 Instances:

#!/bin/bash
# Create an EC2 instance
aws ec2 run-instances \
  --image-id ami-0abcdef1234567890 \
  --count 1 \
  --instance-type t2.micro \
  --key-name MyKeyPair

# List all EC2 instances
aws ec2 describe-instances --output table

Common Issues with Microsoft Azure and AWS CLI Commands

IssueAzure CLI ResolutionAWS CLI Resolution
Authentication ErrorsEnsure az login is successful and check az account showVerify aws configure settings and IAM permissions
Command Not FoundEnsure Azure CLI is installed and the path is set correctlyConfirm AWS CLI installation and check the PATH environment variable
Insufficient PermissionsCheck role assignments and access policies with az role assignment listReview IAM policies and roles using aws iam list-roles
Network IssuesVerify network connectivity and configure proxies if neededCheck VPC, security groups, and internet connectivity
Rate LimitsImplement retry logic in scripts and check Azure subscription limitsUse exponential backoff in scripts and monitor AWS service limits
Resource Not FoundDouble-check resource names and IDs; use az resource listVerify resource IDs and names; use aws resourcegroupstaggingapi get-resources
Invalid ParametersRefer to Azure CLI documentation for correct parametersUse AWS CLI help (aws <command> help) for correct syntax
TimeoutsIncrease timeout settings with --timeout option in commandsAdjust timeout settings in AWS CLI configuration

Thank You

Read More

https://devopsden.io/article/what-is-microsoft-azure

Follow us on

https://www.linkedin.com/company/devopsden/

Table of Contents

    Subscribe to Us

    Always Get Notified