New batchZero to DevOps starts 29 Nov · limited seatsReserve your seat
Cheat sheetsAWSAWS
FreeSheet 02 of 7

Compute Services

A comprehensive developer cheatsheet covering AWS core compute services, including EC2, Lambda, ECS, EKS, Auto Scaling, and Elastic Load Balancing (ALB).

EC2 — Elastic Compute Cloud

EC2 provides resizable virtual servers (instances) in the cloud.

Listing & Describing Instances

List All EC2 Instances:

bash
$ aws ec2 describe-instances
{
    "Reservations": [
        {
            "Instances": [
                {
                    "InstanceId": "i-0dae5d4daa47fe4a2",
                    "InstanceType": "t2.micro",
                    "State": {
                        "Name": "running"
                    },
                    "PublicIpAddress": "54.123.45.67",
                    "PrivateIpAddress": "10.0.1.100",
                    "LaunchTime": "2026-01-15T10:30:15.000Z"
                }
            ]
        }
    ]
}

Lists all EC2 instances with their details.

Filtered Query for Instance IDs and Names:

bash
$ aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId,InstanceType,State.Name,Tags[?Key==`Name`].Value]' --output table
|-------------------------------------------------|
|  i-0dae5d4daa47fe4a2 | t2.micro | running | web-server |
|  i-1bcf6e5ebf68fe5b3 | t3.medium | stopped | db-server |

--query with JMESPath filters output to show only specific fields.

List Instances with Specific State:

bash
$ aws ec2 describe-instances --filters Name=instance-state-name,Values=running --query 'Reservations[*].Instances[*].[InstanceId,InstanceType]' --output table

List Instances by Tag:

bash
$ aws ec2 describe-instances --filters Name=tag:Environment,Values=production --query 'Reservations[*].Instances[*].[InstanceId,Tags[?Key==`Name`].Value]' --output table

Managing EC2 Instances

Start an EC2 Instance:

bash
$ aws ec2 start-instances --instance-ids i-0dae5d4daa47fe4a2
{
    "StartingInstances": [
        {
            "InstanceId": "i-0dae5d4daa47fe4a2",
            "CurrentState": {
                "Name": "pending"
            },
            "PreviousState": {
                "Name": "stopped"
            }
        }
    ]
}

Starts a stopped EC2 instance.

Stop an EC2 Instance:

bash
$ aws ec2 stop-instances --instance-ids i-0dae5d4daa47fe4a2
{
    "StoppingInstances": [
        {
            "InstanceId": "i-0dae5d4daa47fe4a2",
            "CurrentState": {
                "Name": "stopping"
            },
            "PreviousState": {
                "Name": "running"
            }
        }
    ]
}

Reboot an EC2 Instance:

bash
$ aws ec2 reboot-instances --instance-ids i-0dae5d4daa47fe4a2
(No output on success)

Terminate an EC2 Instance:

bash
$ aws ec2 terminate-instances --instance-ids i-0dae5d4daa47fe4a2
{
    "TerminatingInstances": [
        {
            "InstanceId": "i-0dae5d4daa47fe4a2",
            "CurrentState": {
                "Name": "shutting-down"
            },
            "PreviousState": {
                "Name": "running"
            }
        }
    ]
}

** Permanently deletes the instance** — cannot be recovered!

Wait for Instance State Change:

bash
$ aws ec2 wait instance-running --instance-ids i-0dae5d4daa47fe4a2
(No output — waits until instance is running)

$ aws ec2 wait instance-stopped --instance-ids i-0dae5d4daa47fe4a2
(No output — waits until instance is stopped)

$ aws ec2 wait instance-terminated --instance-ids i-0dae5d4daa47fe4a2
(No output — waits until instance is terminated)

Creating & Launching EC2 Instances

Launch a New EC2 Instance:

bash
$ aws ec2 run-instances \
    --image-id ami-0abcdef1234567890 \
    --instance-type t2.micro \
    --key-name my-key-pair \
    --security-group-ids sg-12345678 \
    --subnet-id subnet-12345678 \
    --user-data file://user-data.sh \
    --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=web-server},{Key=Environment,Value=production}]'

{
    "Instances": [
        {
            "InstanceId": "i-0dae5d4daa47fe4a2",
            "InstanceType": "t2.micro",
            "State": {
                "Name": "pending"
            },
            "PrivateIpAddress": "10.0.1.100",
            "PublicIpAddress": "54.123.45.67"
        }
    ]
}

Launches a new EC2 instance with specified parameters.

Get AMI ID from SSM Parameter Store (Amazon Linux 2):

bash
$ aws ssm get-parameters --names /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2 --query 'Parameters[0].Value' --output text
ami-0abcdef1234567890

Get AMI ID for Ubuntu 22.04:

bash
$ aws ec2 describe-images --owners 099720109477 --filters "Name=name,Values=ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*" "Name=state,Values=available" --query 'Images[*].[ImageId,CreationDate]' --output table | sort -k2 -r | head -1
ami-0abcdef1234567890  2026-01-15T10:30:15.000Z

EC2 Key Pairs

List Key Pairs:

bash
$ aws ec2 describe-key-pairs --query 'KeyPairs[*].[KeyName]' --output table
|------------------|
| my-key-pair      |
| production-key   |

Create a New Key Pair:

bash
$ aws ec2 create-key-pair --key-name new-key --query 'KeyMaterial' --output text > new-key.pem
chmod 400 new-key.pem

Creates a new key pair and saves the private key to a file. The private key is only shown once!

Delete a Key Pair:

bash
$ aws ec2 delete-key-pair --key-name new-key

Security Groups

List Security Groups:

bash
$ aws ec2 describe-security-groups --query 'SecurityGroups[*].[GroupId,GroupName,Description]' --output table
|-----------------|---------------|-----------------------------|
| sg-12345678     | web-sg        | Web server security group   |
| sg-87654321     | db-sg         | Database security group     |

Create a Security Group:

bash
$ aws ec2 create-security-group --group-name app-sg --description "Application security group" --vpc-id vpc-12345678
{
    "GroupId": "sg-abcdef1234567890"
}

Add Inbound Rule (Allow SSH from anywhere):

bash
$ aws ec2 authorize-security-group-ingress --group-id sg-abcdef1234567890 --protocol tcp --port 22 --cidr 0.0.0.0/0

Add Inbound Rule (Allow HTTP from anywhere):

bash
$ aws ec2 authorize-security-group-ingress --group-id sg-abcdef1234567890 --protocol tcp --port 80 --cidr 0.0.0.0/0

Add Inbound Rule (Allow HTTPS from anywhere):

bash
$ aws ec2 authorize-security-group-ingress --group-id sg-abcdef1234567890 --protocol tcp --port 443 --cidr 0.0.0.0/0

Add Inbound Rule (Allow from another Security Group):

bash
$ aws ec2 authorize-security-group-ingress --group-id sg-abcdef1234567890 --protocol tcp --port 3306 --source-group sg-87654321

Remove Inbound Rule:

bash
$ aws ec2 revoke-security-group-ingress --group-id sg-abcdef1234567890 --protocol tcp --port 22 --cidr 0.0.0.0/0

Delete Security Group:

bash
$ aws ec2 delete-security-group --group-id sg-abcdef1234567890

** Security group must not be associated with any instances.**

EC2 Instance Metadata

Get Instance Metadata (from inside the instance):

bash
$ curl http://169.254.169.254/latest/meta-data/
ami-id
ami-launch-index
instance-id
instance-type
local-hostname
local-ipv4
public-hostname
public-ipv4
security-groups

Get Specific Metadata:

bash
$ curl http://169.254.169.254/latest/meta-data/instance-id
i-0dae5d4daa47fe4a2

$ curl http://169.254.169.254/latest/meta-data/public-ipv4
54.123.45.67

Get User Data:

bash
$ curl http://169.254.169.254/latest/user-data
#!/bin/bash
yum update -y
yum install nginx -y
service nginx start

Lambda — Serverless Functions

Lambda runs code without provisioning servers. Supports Python, Node.js, Java, Go, .NET, Ruby.

Listing & Managing Functions

List Lambda Functions:

bash
$ aws lambda list-functions --query 'Functions[*].[FunctionName,Runtime,Handler,MemorySize,LastModified]' --output table
|------------------|----------|------------------|-----------|----------------------|
| my-lambda        | python3.9| lambda_function.handler | 128 | 2026-01-15T10:30:15.000Z |
| api-handler      | nodejs18.x| index.handler     | 256 | 2026-01-14T10:30:15.000Z |

Get Function Details:

bash
$ aws lambda get-function --function-name my-lambda
{
    "Configuration": {
        "FunctionName": "my-lambda",
        "FunctionArn": "arn:aws:lambda:us-east-1:123456789012:function:my-lambda",
        "Runtime": "python3.9",
        "Handler": "lambda_function.handler",
        "MemorySize": 128,
        "Timeout": 30,
        "LastModified": "2026-01-15T10:30:15.000Z"
    },
    "Code": {
        "Location": "https://lambda.../my-lambda"
    }
}

Invoking Lambda Functions

Invoke Lambda (Synchronous):

bash
$ aws lambda invoke --function-name my-lambda --payload '{"key":"value"}' response.json
{
    "StatusCode": 200,
    "ExecutedVersion": "$LATEST"
}

$ cat response.json
{"status":"success","message":"Hello from Lambda"}

Executes a Lambda function synchronously and saves output to response.json.

Invoke Lambda (Asynchronous — Fire and Forget):

bash
$ aws lambda invoke --function-name my-lambda --invocation-type Event --payload '{"key":"value"}' response.json
{
    "StatusCode": 202
}

Invoke Lambda with CLI (No Payload):

bash
$ aws lambda invoke --function-name my-lambda response.json

Creating & Updating Lambda Functions

Create Lambda Function (Python):

bash
$ aws lambda create-function \
    --function-name my-new-lambda \
    --runtime python3.9 \
    --role arn:aws:iam::123456789012:role/LambdaExecutionRole \
    --handler lambda_function.handler \
    --zip-file fileb://function.zip \
    --memory-size 256 \
    --timeout 30

{
    "FunctionName": "my-new-lambda",
    "FunctionArn": "arn:aws:lambda:us-east-1:123456789012:function:my-new-lambda",
    "Runtime": "python3.9",
    "Handler": "lambda_function.handler",
    "MemorySize": 256,
    "Timeout": 30,
    "LastModified": "2026-01-15T10:30:15.000Z"
}

Update Lambda Code:

bash
$ aws lambda update-function-code --function-name my-new-lambda --zip-file fileb://updated-function.zip
{
    "FunctionName": "my-new-lambda",
    "LastModified": "2026-01-15T10:30:20.000Z",
    "CodeSize": 123456
}

Update Lambda Configuration:

bash
$ aws lambda update-function-configuration --function-name my-new-lambda --memory-size 512 --timeout 60

Add Environment Variable:

bash
$ aws lambda update-function-configuration --function-name my-new-lambda --environment 'Variables={ENV=production,LOG_LEVEL=debug}'

Update Environment Variables Only:

bash
$ aws lambda update-function-configuration --function-name my-new-lambda --environment 'Variables={ENV=staging}'

Lambda Permissions

Add Permission (Allow S3 to Invoke):

bash
$ aws lambda add-permission \
    --function-name my-lambda \
    --statement-id s3-invoke \
    --action lambda:InvokeFunction \
    --principal s3.amazonaws.com \
    --source-arn arn:aws:s3:::my-bucket
{
    "Statement": "{\"Sid\":\"s3-invoke\",\"Effect\":\"Allow\",\"Principal\":{\"Service\":\"s3.amazonaws.com\"},\"Action\":\"lambda:InvokeFunction\",\"Resource\":\"arn:aws:lambda:us-east-1:123456789012:function:my-lambda\",\"Condition\":{\"ArnLike\":{\"AWS:SourceArn\":\"arn:aws:s3:::my-bucket\"}}}"
}

Remove Permission:

bash
$ aws lambda remove-permission --function-name my-lambda --statement-id s3-invoke

Lambda Logging (CloudWatch)

Get Lambda Logs:

bash
$ aws logs describe-log-groups --log-group-name-prefix /aws/lambda/my-lambda
{
    "logGroups": [
        {
            "logGroupName": "/aws/lambda/my-lambda",
            "creationTime": 1234567890123
        }
    ]
}

Get Log Streams:

bash
$ aws logs describe-log-streams --log-group-name /aws/lambda/my-lambda

View Recent Logs:

bash
$ aws logs get-log-events --log-group-name /aws/lambda/my-lambda --log-stream-name "2026/01/15/[$LATEST]abcdef" --limit 10

ECS — Elastic Container Service

ECS is a managed container orchestration service for Docker containers.

Clusters

List ECS Clusters:

bash
$ aws ecs list-clusters
{
    "clusterArns": [
        "arn:aws:ecs:us-east-1:123456789012:cluster/my-cluster",
        "arn:aws:ecs:us-east-1:123456789012:cluster/production"
    ]
}

Describe a Cluster:

bash
$ aws ecs describe-clusters --clusters my-cluster
{
    "clusters": [
        {
            "clusterName": "my-cluster",
            "status": "ACTIVE",
            "registeredContainerInstancesCount": 3,
            "runningTasksCount": 5,
            "pendingTasksCount": 0
        }
    ]
}

Create a New Cluster:

bash
$ aws ecs create-cluster --cluster-name new-cluster
{
    "cluster": {
        "clusterName": "new-cluster",
        "status": "ACTIVE"
    }
}

Delete a Cluster:

bash
$ aws ecs delete-cluster --cluster new-cluster

** Cluster must have no services or tasks running.**

Services

List Services in a Cluster:

bash
$ aws ecs list-services --cluster my-cluster
{
    "serviceArns": [
        "arn:aws:ecs:us-east-1:123456789012:service/my-cluster/web-service",
        "arn:aws:ecs:us-east-1:123456789012:service/my-cluster/api-service"
    ]
}

Describe a Service:

bash
$ aws ecs describe-services --cluster my-cluster --services web-service
{
    "services": [
        {
            "serviceName": "web-service",
            "status": "ACTIVE",
            "desiredCount": 3,
            "runningCount": 3,
            "pendingCount": 0,
            "taskDefinition": "web-task:5"
        }
    ]
}

Create a Service (Fargate):

bash
$ aws ecs create-service \
    --cluster my-cluster \
    --service-name web-service \
    --task-definition web-task:1 \
    --desired-count 3 \
    --launch-type FARGATE \
    --network-configuration "awsvpcConfiguration={subnets=[subnet-12345678],securityGroups=[sg-12345678],assignPublicIp=ENABLED}"

{
    "service": {
        "serviceName": "web-service",
        "status": "ACTIVE",
        "desiredCount": 3,
        "runningCount": 0
    }
}

Update Service (Scale Tasks):

bash
$ aws ecs update-service --cluster my-cluster --service web-service --desired-count 5
{
    "service": {
        "serviceName": "web-service",
        "desiredCount": 5,
        "runningCount": 3
    }
}

Update Service (Force New Deployment):

bash
$ aws ecs update-service --cluster my-cluster --service web-service --force-new-deployment

Delete a Service:

bash
$ aws ecs delete-service --cluster my-cluster --service web-service

** Use --force to delete without confirmation.**

Task Definitions

List Task Definitions:

bash
$ aws ecs list-task-definitions
{
    "taskDefinitionArns": [
        "arn:aws:ecs:us-east-1:123456789012:task-definition/web-task:1",
        "arn:aws:ecs:us-east-1:123456789012:task-definition/web-task:2",
        "arn:aws:ecs:us-east-1:123456789012:task-definition/api-task:1"
    ]
}

Register a Task Definition (Fargate):

bash
$ aws ecs register-task-definition \
    --family web-task \
    --network-mode awsvpc \
    --requires-compatibilities FARGATE \
    --cpu 256 \
    --memory 512 \
    --execution-role-arn arn:aws:iam::123456789012:role/ecsTaskExecutionRole \
    --container-definitions file://container-def.json

Example container-def.json:

json
[
    {
        "name": "web-container",
        "image": "nginx:latest",
        "cpu": 256,
        "memory": 512,
        "essential": true,
        "portMappings": [
            {
                "containerPort": 80,
                "protocol": "tcp"
            }
        ],
        "environment": [
            {
                "name": "ENV",
                "value": "production"
            }
        ]
    }
]

Deregister Task Definition:

bash
$ aws ecs deregister-task-definition --task-definition web-task:1

Tasks

Run a Task (One-off):

bash
$ aws ecs run-task --cluster my-cluster --task-definition web-task:1
{
    "tasks": [
        {
            "taskArn": "arn:aws:ecs:us-east-1:123456789012:task/my-cluster/abc123",
            "desiredStatus": "RUNNING",
            "lastStatus": "RUNNING"
        }
    ]
}

List Running Tasks:

bash
$ aws ecs list-tasks --cluster my-cluster
{
    "taskArns": [
        "arn:aws:ecs:us-east-1:123456789012:task/my-cluster/abc123"
    ]
}

Stop a Task:

bash
$ aws ecs stop-task --cluster my-cluster --task abc123

EKS — Elastic Kubernetes Service

EKS is a managed Kubernetes service.

Clusters

List EKS Clusters:

bash
$ aws eks list-clusters
{
    "clusters": ["my-eks-cluster", "production-cluster"]
}

Describe an EKS Cluster:

bash
$ aws eks describe-cluster --name my-eks-cluster
{
    "cluster": {
        "name": "my-eks-cluster",
        "arn": "arn:aws:eks:us-east-1:123456789012:cluster/my-eks-cluster",
        "status": "ACTIVE",
        "version": "1.28",
        "endpoint": "https://EKS_ENDPOINT.yl4.us-east-1.eks.amazonaws.com",
        "createdAt": "2026-01-15T10:30:15.000Z",
        "platformVersion": "eks.5"
    }
}

Update Kubeconfig for EKS:

bash
$ aws eks update-kubeconfig --name my-eks-cluster
Added new context arn:aws:eks:us-east-1:123456789012:cluster/my-eks-cluster to ~/.kube/config

Configures kubectl to connect to your EKS cluster.

Update Kubeconfig for Specific Profile:

bash
$ aws eks update-kubeconfig --name my-eks-cluster --profile production

Create an EKS Cluster:

bash
$ aws eks create-cluster \
    --name new-eks-cluster \
    --role-arn arn:aws:iam::123456789012:role/eks-cluster-role \
    --resources-vpc-config subnetIds=subnet-12345678,subnet-87654321,securityGroupIds=sg-12345678

{
    "cluster": {
        "name": "new-eks-cluster",
        "status": "CREATING"
    }
}

Wait for Cluster Creation:

bash
$ aws eks wait cluster-active --name new-eks-cluster

Delete EKS Cluster:

bash
$ aws eks delete-cluster --name new-eks-cluster
{
    "cluster": {
        "name": "new-eks-cluster",
        "status": "DELETING"
    }
}

** Deleting a cluster is irreversible.**

Node Groups

List Node Groups:

bash
$ aws eks list-nodegroups --cluster-name my-eks-cluster
{
    "nodegroups": ["managed-ng-1", "managed-ng-2"]
}

Describe Node Group:

bash
$ aws eks describe-nodegroup --cluster-name my-eks-cluster --nodegroup-name managed-ng-1
{
    "nodegroup": {
        "nodegroupName": "managed-ng-1",
        "status": "ACTIVE",
        "instanceTypes": ["t3.medium"],
        "desiredSize": 3,
        "minSize": 2,
        "maxSize": 5
    }
}

Create Node Group:

bash
$ aws eks create-nodegroup \
    --cluster-name my-eks-cluster \
    --nodegroup-name new-ng \
    --subnets subnet-12345678 \
    --node-role arn:aws:iam::123456789012:role/eks-node-role \
    --instance-types t3.medium \
    --desired-size 3

Update Node Group (Scale):

bash
$ aws eks update-nodegroup-config --cluster-name my-eks-cluster --nodegroup-name new-ng --desired-size 5

Delete Node Group:

bash
$ aws eks delete-nodegroup --cluster-name my-eks-cluster --nodegroup-name new-ng

Auto Scaling

EC2 Auto Scaling

List Auto Scaling Groups:

bash
$ aws autoscaling describe-auto-scaling-groups --query 'AutoScalingGroups[*].[AutoScalingGroupName,DesiredCapacity,MinSize,MaxSize]' --output table
|------------------|-----------------|---------|---------|
| web-asg          | 3               | 2       | 10      |
| db-asg           | 1               | 1       | 3       |

Describe Auto Scaling Group:

bash
$ aws autoscaling describe-auto-scaling-groups --auto-scaling-group-names web-asg
{
    "AutoScalingGroups": [
        {
            "AutoScalingGroupName": "web-asg",
            "DesiredCapacity": 3,
            "MinSize": 2,
            "MaxSize": 10,
            "LaunchTemplate": {
                "LaunchTemplateName": "web-launch-template",
                "Version": "$Latest"
            }
        }
    ]
}

Update Auto Scaling Group (Change Desired Capacity):

bash
$ aws autoscaling set-desired-capacity --auto-scaling-group-name web-asg --desired-capacity 5

Update Auto Scaling Group (Change Min/Max):

bash
$ aws autoscaling update-auto-scaling-group --auto-scaling-group-name web-asg --min-size 3 --max-size 15

Create Auto Scaling Group:

bash
$ aws autoscaling create-auto-scaling-group \
    --auto-scaling-group-name new-asg \
    --launch-template LaunchTemplateName=web-launch-template,Version='$Latest' \
    --min-size 2 \
    --max-size 10 \
    --desired-capacity 3 \
    --vpc-zone-identifier "subnet-12345678,subnet-87654321"

Delete Auto Scaling Group:

bash
$ aws autoscaling delete-auto-scaling-group --auto-scaling-group-name new-asg

** Use --force-delete to delete even with instances.**

Launch Templates

Create Launch Template:

bash
$ aws ec2 create-launch-template \
    --launch-template-name web-launch-template \
    --launch-template-data file://template-data.json

Example template-data.json:

json
{
    "ImageId": "ami-0abcdef1234567890",
    "InstanceType": "t3.medium",
    "SecurityGroupIds": ["sg-12345678"],
    "UserData": "IyEvYmluL2Jhc2gK..."
}

Elastic Load Balancing (ELB)

Application Load Balancer (ALB)

List Load Balancers:

bash
$ aws elbv2 describe-load-balancers --query 'LoadBalancers[*].[LoadBalancerName,DNSName,State.Code,Type]' --output table
|------------------|---------------------------|---------|----------|
| web-alb          | web-alb-123456.elb.amazonaws.com | active | application |
| internal-api     | internal-api-123456.elb.amazonaws.com | active | application |

Create Application Load Balancer:

bash
$ aws elbv2 create-load-balancer \
    --name web-alb \
    --subnets subnet-12345678 subnet-87654321 \
    --security-groups sg-12345678 \
    --scheme internet-facing

{
    "LoadBalancers": [
        {
            "LoadBalancerName": "web-alb",
            "DNSName": "web-alb-123456.elb.amazonaws.com",
            "State": {
                "Code": "provisioning"
            }
        }
    ]
}

Create Target Group:

bash
$ aws elbv2 create-target-group \
    --name web-targets \
    --protocol HTTP \
    --port 80 \
    --vpc-id vpc-12345678 \
    --health-check-path /health

{
    "TargetGroups": [
        {
            "TargetGroupName": "web-targets",
            "TargetGroupArn": "arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/web-targets/1234567890"
        }
    ]
}

Create Listener:

bash
$ aws elbv2 create-listener \
    --load-balancer-arn arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/app/web-alb/1234567890 \
    --protocol HTTP \
    --port 80 \
    --default-actions Type=forward,TargetGroupArn=arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/web-targets/1234567890

{
    "Listeners": [
        {
            "ListenerArn": "arn:aws:elasticloadbalancing:us-east-1:123456789012:listener/app/web-alb/1234567890/1234567890",
            "Port": 80,
            "Protocol": "HTTP"
        }
    ]
}

Register Targets with Target Group:

bash
$ aws elbv2 register-targets \
    --target-group-arn arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/web-targets/1234567890 \
    --targets Id=i-0dae5d4daa47fe4a2 Id=i-1bcf6e5ebf68fe5b3

Deregister Targets:

bash
$ aws elbv2 deregister-targets \
    --target-group-arn arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/web-targets/1234567890 \
    --targets Id=i-0dae5d4daa47fe4a2

Delete Load Balancer:

bash
$ aws elbv2 delete-load-balancer --load-balancer-arn arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/app/web-alb/1234567890

Quick Reference — Most Used Commands

TaskCommand
List EC2 instancesaws ec2 describe-instances
Start EC2aws ec2 start-instances --instance-ids i-xxx
Stop EC2aws ec2 stop-instances --instance-ids i-xxx
Terminate EC2aws ec2 terminate-instances --instance-ids i-xxx
List security groupsaws ec2 describe-security-groups
Add security group ruleaws ec2 authorize-security-group-ingress --group-id sg-xxx --protocol tcp --port 80 --cidr 0.0.0.0/0
List Lambda functionsaws lambda list-functions
Invoke Lambdaaws lambda invoke --function-name fn response.json
List ECS clustersaws ecs list-clusters
Update ECS serviceaws ecs update-service --cluster cluster --service service --desired-count 5
List EKS clustersaws eks list-clusters
Update kubeconfigaws eks update-kubeconfig --name cluster
List ASGsaws autoscaling describe-auto-scaling-groups
Update ASG desiredaws autoscaling set-desired-capacity --auto-scaling-group-name asg --desired-capacity 5
List ALBsaws elbv2 describe-load-balancers
Register targetsaws elbv2 register-targets --target-group-arn arn --targets Id=i-xxx

Additional Tips

  1. Use --dry-run Before Destructive Commands:

    bash
    aws ec2 terminate-instances --instance-ids i-xxx --dry-run
  2. Use --query for Filtering:

    bash
    aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId,State.Name]'
  3. Use jq for Parsing JSON:

    bash
    aws ec2 describe-instances | jq -r '.Reservations[].Instances[].InstanceId'
  4. EC2 User Data runs only on first boot. Use cloud-init for persistent configuration.

  5. Lambda Timeout: Max 15 minutes. Use Step Functions for long-running workflows.

  6. ECS vs EKS: ECS is simpler (AWS proprietary). EKS is standard Kubernetes (portable).

  7. Fargate vs EC2 Launch Types: Fargate is serverless (no EC2 management). EC2 gives more control.


Next in AWSStorage Services
AWS cheat sheet: Compute Services | InfraThrone DevOps Park