Skip to content

Commit 1a1c462

Browse files
committed
Add compute tutorials (batch 6)
1 parent 49f07d9 commit 1a1c462

5 files changed

Lines changed: 34 additions & 0 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
WORK_DIR=$(mktemp -d); exec > >(tee -a "$WORK_DIR/tut.log") 2>&1
3+
REGION=${AWS_DEFAULT_REGION:-$(aws configure get region 2>/dev/null)}; [ -z "$REGION" ] && echo "ERROR: No region" && exit 1; export AWS_DEFAULT_REGION="$REGION"; echo "Region: $REGION"
4+
echo "Step 1: Listing all instances"; aws ec2 describe-instances --query 'Reservations[].Instances[].{Id:InstanceId,Type:InstanceType,State:State.Name,Name:Tags[?Key==`Name`].Value|[0]}' --output table 2>/dev/null || echo " No instances"
5+
echo "Step 2: Counting by state"; aws ec2 describe-instances --query 'Reservations[].Instances[].State.Name' --output text | tr '\t' '\n' | sort | uniq -c
6+
echo ""; echo "Tutorial complete. Read-only."; rm -rf "$WORK_DIR"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
WORK_DIR=$(mktemp -d); exec > >(tee -a "$WORK_DIR/tut.log") 2>&1
3+
REGION=${AWS_DEFAULT_REGION:-$(aws configure get region 2>/dev/null)}; [ -z "$REGION" ] && echo "ERROR: No region" && exit 1; export AWS_DEFAULT_REGION="$REGION"; echo "Region: $REGION"
4+
echo "Step 1: Listing VPCs"; aws ec2 describe-vpcs --query 'Vpcs[].{Id:VpcId,CIDR:CidrBlock,Default:IsDefault}' --output table
5+
echo "Step 2: Listing subnets"; aws ec2 describe-subnets --query 'Subnets[:10].{Id:SubnetId,VPC:VpcId,AZ:AvailabilityZone,CIDR:CidrBlock}' --output table
6+
echo "Step 3: Listing route tables"; aws ec2 describe-route-tables --query 'RouteTables[:5].{Id:RouteTableId,VPC:VpcId,Routes:Routes|length(@)}' --output table
7+
echo "Step 4: Listing internet gateways"; aws ec2 describe-internet-gateways --query 'InternetGateways[:5].{Id:InternetGatewayId,VPC:Attachments[0].VpcId}' --output table
8+
echo ""; echo "Tutorial complete. Read-only."; rm -rf "$WORK_DIR"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
WORK_DIR=$(mktemp -d); exec > >(tee -a "$WORK_DIR/tut.log") 2>&1
3+
REGION=${AWS_DEFAULT_REGION:-$(aws configure get region 2>/dev/null)}; [ -z "$REGION" ] && echo "ERROR: No region" && exit 1; export AWS_DEFAULT_REGION="$REGION"; echo "Region: $REGION"
4+
echo "Step 1: Listing Lambda log groups"; aws logs describe-log-groups --log-group-name-prefix /aws/lambda --query 'logGroups[:10].{Name:logGroupName,Stored:storedBytes,Retention:retentionInDays}' --output table
5+
echo "Step 2: Getting recent log events from a function"
6+
LG=$(aws logs describe-log-groups --log-group-name-prefix /aws/lambda --query 'logGroups[0].logGroupName' --output text 2>/dev/null)
7+
[ -n "$LG" ] && [ "$LG" != "None" ] && { LS=$(aws logs describe-log-streams --log-group-name "$LG" --order-by LastEventTime --descending --limit 1 --query 'logStreams[0].logStreamName' --output text); aws logs get-log-events --log-group-name "$LG" --log-stream-name "$LS" --limit 5 --query 'events[].message' --output text; } || echo " No Lambda log groups"
8+
echo ""; echo "Tutorial complete. Read-only."; rm -rf "$WORK_DIR"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
WORK_DIR=$(mktemp -d); exec > >(tee -a "$WORK_DIR/tut.log") 2>&1
3+
REGION=${AWS_DEFAULT_REGION:-$(aws configure get region 2>/dev/null)}; [ -z "$REGION" ] && echo "ERROR: No region" && exit 1; export AWS_DEFAULT_REGION="$REGION"; echo "Region: $REGION"
4+
echo "Step 1: Listing network interfaces"; aws ec2 describe-network-interfaces --query 'NetworkInterfaces[:10].{Id:NetworkInterfaceId,Type:InterfaceType,Status:Status,SubnetId:SubnetId}' --output table
5+
echo "Step 2: Counting by type"; aws ec2 describe-network-interfaces --query 'NetworkInterfaces[].InterfaceType' --output text | tr '\t' '\n' | sort | uniq -c | sort -rn
6+
echo ""; echo "Tutorial complete. Read-only."; rm -rf "$WORK_DIR"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
WORK_DIR=$(mktemp -d); exec > >(tee -a "$WORK_DIR/tut.log") 2>&1
3+
REGION=${AWS_DEFAULT_REGION:-$(aws configure get region 2>/dev/null)}; [ -z "$REGION" ] && echo "ERROR: No region" && exit 1; export AWS_DEFAULT_REGION="$REGION"; echo "Region: $REGION"
4+
echo "Step 1: Listing volumes"; aws ec2 describe-volumes --query 'Volumes[:10].{Id:VolumeId,Type:VolumeType,Size:Size,State:State,AZ:AvailabilityZone}' --output table
5+
echo "Step 2: Volume summary"; echo " Total: $(aws ec2 describe-volumes --query 'Volumes | length(@)' --output text) volumes"
6+
echo ""; echo "Tutorial complete. Read-only."; rm -rf "$WORK_DIR"

0 commit comments

Comments
 (0)