Skip to content

Commit 5a685fb

Browse files
committed
Add compute tutorials (batch 5)
1 parent 49f07d9 commit 5a685fb

5 files changed

Lines changed: 77 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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 EBS volume types"
5+
echo " gp3: General Purpose SSD (default)"
6+
echo " gp2: Previous gen General Purpose SSD"
7+
echo " io2: Provisioned IOPS SSD"
8+
echo " st1: Throughput Optimized HDD"
9+
echo " sc1: Cold HDD"
10+
echo "Step 2: Listing your volumes by type"
11+
aws ec2 describe-volumes --query "Volumes[].{Id:VolumeId,Type:VolumeType,Size:Size,State:State,IOPS:Iops}" --output table 2>/dev/null || echo " No volumes"
12+
echo "Step 3: Describing volume modifications"
13+
aws ec2 describe-volumes-modifications --query "VolumesModifications[:5].{Id:VolumeId,Status:ModificationState,OrigType:OriginalVolumeType,TargetType:TargetVolumeType}" --output table 2>/dev/null || echo " No modifications"
14+
echo ""; echo "Tutorial complete. No resources created — read-only."
15+
rm -rf "$WORK_DIR"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
RANDOM_ID=$(openssl rand -hex 4); F="dlq-func-${RANDOM_ID}"; R="dlq-func-role-${RANDOM_ID}"; Q="dlq-func-q-${RANDOM_ID}"
5+
handle_error() { echo "ERROR on line $1"; trap - ERR; cleanup; exit 1; }; trap 'handle_error $LINENO' ERR
6+
cleanup() { echo "Cleaning up..."; aws lambda delete-function --function-name "$F" 2>/dev/null; [ -n "$QU" ] && aws sqs delete-queue --queue-url "$QU" 2>/dev/null; aws iam detach-role-policy --role-name "$R" --policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole 2>/dev/null; aws iam detach-role-policy --role-name "$R" --policy-arn arn:aws:iam::aws:policy/AmazonSQSFullAccess 2>/dev/null; aws iam delete-role --role-name "$R" 2>/dev/null; rm -rf "$WORK_DIR"; echo "Done."; }
7+
RA=$(aws iam create-role --role-name "$R" --assume-role-policy-document '{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"Service":"lambda.amazonaws.com"},"Action":"sts:AssumeRole"}]}' --query Role.Arn --output text)
8+
aws iam attach-role-policy --role-name "$R" --policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
9+
aws iam attach-role-policy --role-name "$R" --policy-arn arn:aws:iam::aws:policy/AmazonSQSFullAccess; sleep 10
10+
QU=$(aws sqs create-queue --queue-name "$Q" --query QueueUrl --output text)
11+
QA=$(aws sqs get-queue-attributes --queue-url "$QU" --attribute-names QueueArn --query Attributes.QueueArn --output text)
12+
echo "Step 1: Creating function that always fails"
13+
echo "def handler(e,c): raise Exception('Intentional failure')" > "$WORK_DIR/i.py"
14+
(cd "$WORK_DIR" && zip f.zip i.py > /dev/null)
15+
aws lambda create-function --function-name "$F" --zip-file "fileb://$WORK_DIR/f.zip" --handler i.handler --runtime python3.12 --role "$RA" --dead-letter-config "{\"TargetArn\":\"$QA\"}" --architectures x86_64 > /dev/null
16+
aws lambda wait function-active-v2 --function-name "$F"
17+
echo " Function with DLQ configured"
18+
echo "Step 2: Invoking async (will fail and go to DLQ)"
19+
aws lambda invoke --function-name "$F" --invocation-type Event --cli-binary-format raw-in-base64-out --payload '{}' "$WORK_DIR/out.json" > /dev/null
20+
echo " Invoked async — Lambda will retry twice then send to DLQ"
21+
echo "Step 3: Checking DLQ (after retries, ~3 min)"
22+
echo " DLQ messages: $(aws sqs get-queue-attributes --queue-url "$QU" --attribute-names ApproximateNumberOfMessages --query Attributes.ApproximateNumberOfMessages --output text)"
23+
echo " (Message will appear after Lambda exhausts retries)"
24+
echo ""; echo "Tutorial complete."
25+
echo "Do you want to clean up? (y/n): "; read -r C; [[ "$C" =~ ^[Yy]$ ]] && cleanup
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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 instance type families"
5+
aws ec2 describe-instance-types --filters "Name=instance-type,Values=t3.*" --query 'InstanceTypes[].{Type:InstanceType,vCPUs:VCpuInfo.DefaultVCpus,Memory:MemoryInfo.SizeInMiB}' --output table
6+
echo "Step 2: Describing a specific type"
7+
aws ec2 describe-instance-types --instance-types t3.micro --query 'InstanceTypes[0].{Type:InstanceType,vCPUs:VCpuInfo.DefaultVCpus,Memory:MemoryInfo.SizeInMiB,Network:NetworkInfo.NetworkPerformance,Arch:ProcessorInfo.SupportedArchitectures}' --output table
8+
echo "Step 3: Finding instances by criteria"
9+
aws ec2 describe-instance-types --filters "Name=vcpu-info.default-vcpus,Values=2" "Name=memory-info.size-in-mib,Values=4096" --query 'InstanceTypes[:5].{Type:InstanceType,vCPUs:VCpuInfo.DefaultVCpus,Memory:MemoryInfo.SizeInMiB}' --output table
10+
echo ""; echo "Tutorial complete. No resources created — read-only."
11+
rm -rf "$WORK_DIR"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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 runtimes"
5+
aws lambda list-layers --compatible-runtime python3.12 --query 'Layers[:5].{Name:LayerName,Version:LatestMatchingVersion.Version}' --output table 2>/dev/null || echo " No compatible layers"
6+
echo "Step 2: Getting Lambda service quotas"
7+
aws lambda get-account-settings --query 'AccountLimit.{CodeSize:TotalCodeSize,ConcurrentExec:ConcurrentExecutions,FunctionCount:FunctionCount}' --output table
8+
echo "Step 3: Listing functions by runtime"
9+
aws lambda list-functions --query 'Functions[?Runtime==`python3.12`][:5].{Name:FunctionName,Runtime:Runtime,Size:CodeSize}' --output table 2>/dev/null || echo " No Python 3.12 functions"
10+
echo "Step 4: Listing event source mappings"
11+
aws lambda list-event-source-mappings --query 'EventSourceMappings[:5].{Function:FunctionArn,Source:EventSourceArn,State:State}' --output table 2>/dev/null || echo " No event source mappings"
12+
echo ""; echo "Tutorial complete. No resources created — read-only."
13+
rm -rf "$WORK_DIR"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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: Describing your running instances"
5+
aws ec2 describe-instances --filters "Name=instance-state-name,Values=running" --query 'Reservations[].Instances[:3].{Id:InstanceId,Type:InstanceType,State:State.Name,AZ:Placement.AvailabilityZone}' --output table 2>/dev/null || echo " No running instances"
6+
echo "Step 2: Describing instance status"
7+
aws ec2 describe-instance-status --query 'InstanceStatuses[:3].{Id:InstanceId,System:SystemStatus.Status,Instance:InstanceStatus.Status}' --output table 2>/dev/null || echo " No instance status"
8+
echo "Step 3: Listing regions"
9+
aws ec2 describe-regions --query 'Regions[:10].{Name:RegionName,Endpoint:Endpoint}' --output table
10+
echo "Step 4: Listing availability zones"
11+
aws ec2 describe-availability-zones --query 'AvailabilityZones[:5].{Zone:ZoneName,State:State,Type:ZoneType}' --output table
12+
echo ""; echo "Tutorial complete. No resources created — read-only."
13+
rm -rf "$WORK_DIR"

0 commit comments

Comments
 (0)