Skip to content

Commit 2b172dc

Browse files
committed
Add mixed tutorials (batch 23)
1 parent 49f07d9 commit 2b172dc

5 files changed

Lines changed: 47 additions & 0 deletions

File tree

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+
RANDOM_ID=$(openssl rand -hex 4); T="tut-batch-${RANDOM_ID}"
5+
cleanup() { aws dynamodb delete-table --table-name "$T" > /dev/null 2>&1; rm -rf "$WORK_DIR"; echo "Done."; }
6+
echo "Step 1: Creating table"; aws dynamodb create-table --table-name "$T" --key-schema AttributeName=pk,KeyType=HASH --attribute-definitions AttributeName=pk,AttributeType=S --billing-mode PAY_PER_REQUEST > /dev/null; aws dynamodb wait table-exists --table-name "$T"
7+
echo "Step 2: Batch write (25 items)"; aws dynamodb batch-write-item --request-items "{\"$T\":[$(for i in $(seq 1 25); do echo -n "{\"PutRequest\":{\"Item\":{\"pk\":{\"S\":\"item-$i\"},\"data\":{\"S\":\"value-$i\"}}}}"; [ $i -lt 25 ] && echo -n ","; done)]}" > /dev/null
8+
echo " Wrote 25 items"
9+
echo "Step 3: Batch get (5 items)"; aws dynamodb batch-get-item --request-items "{\"$T\":{\"Keys\":[{\"pk\":{\"S\":\"item-1\"}},{\"pk\":{\"S\":\"item-5\"}},{\"pk\":{\"S\":\"item-10\"}},{\"pk\":{\"S\":\"item-15\"}},{\"pk\":{\"S\":\"item-20\"}}]}}" --query "Responses.\"$T\"[].{pk:pk.S,data:data.S}" --output table
10+
echo "Step 4: Scan count"; aws dynamodb scan --table-name "$T" --select COUNT --query 'Count' --output text
11+
echo "Do you want to clean up? (y/n): "; read -r C; [[ "$C" =~ ^[Yy]$ ]] && cleanup
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 functions"; aws lambda list-functions --query 'Functions[:10].{Name:FunctionName,Runtime:Runtime,Size:CodeSize,Modified:LastModified}' --output table
5+
echo "Step 2: Function count by runtime"; aws lambda list-functions --query 'Functions[].Runtime' --output text | tr '\t' '\n' | sort | uniq -c | sort -rn
6+
echo ""; echo "Tutorial complete. Read-only."; rm -rf "$WORK_DIR"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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 security groups"; aws ec2 describe-security-groups --query 'SecurityGroups[:10].{Id:GroupId,Name:GroupName,VPC:VpcId,InRules:IpPermissions|length(@),OutRules:IpPermissionsEgress|length(@)}' --output table
5+
echo "Step 2: Finding groups with open SSH"
6+
aws ec2 describe-security-groups --filters "Name=ip-permission.from-port,Values=22" "Name=ip-permission.cidr,Values=0.0.0.0/0" --query 'SecurityGroups[].{Id:GroupId,Name:GroupName}' --output table 2>/dev/null || echo " No groups with open SSH"
7+
echo ""; echo "Tutorial complete. Read-only."; rm -rf "$WORK_DIR"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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 functions with event invoke configs"
5+
for F in $(aws lambda list-functions --query 'Functions[:5].FunctionName' --output text 2>/dev/null); do
6+
CONFIG=$(aws lambda get-function-event-invoke-config --function-name "$F" 2>/dev/null)
7+
[ -n "$CONFIG" ] && echo " $F: $(echo $CONFIG | python3 -c 'import sys,json;c=json.load(sys.stdin);print(f"MaxRetry={c.get(\"MaximumRetryAttempts\",\"default\")}, MaxAge={c.get(\"MaximumEventAgeInSeconds\",\"default\")}")')"
8+
done
9+
echo " (Functions without custom config use defaults: 2 retries, 6 hours max age)"
10+
echo ""; echo "Tutorial complete. Read-only."; 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: Finding stopped instances (still incurring EBS charges)"
5+
aws ec2 describe-instances --filters "Name=instance-state-name,Values=stopped" --query 'Reservations[].Instances[].{Id:InstanceId,Type:InstanceType,Stopped:StateTransitionReason}' --output table 2>/dev/null || echo " No stopped instances"
6+
echo "Step 2: Finding unattached EBS volumes"
7+
aws ec2 describe-volumes --filters "Name=status,Values=available" --query 'Volumes[].{Id:VolumeId,Size:Size,Type:VolumeType,Created:CreateTime}' --output table 2>/dev/null || echo " No unattached volumes"
8+
echo "Step 3: Finding unattached Elastic IPs"
9+
aws ec2 describe-addresses --query 'Addresses[?AssociationId==null].{IP:PublicIp,AllocId:AllocationId}' --output table 2>/dev/null || echo " No unattached EIPs"
10+
echo "Step 4: Finding old snapshots (>90 days)"
11+
CUTOFF=$(date -u -d '90 days ago' +%Y-%m-%dT%H:%M:%SZ)
12+
aws ec2 describe-snapshots --owner-ids self --query "Snapshots[?StartTime<'$CUTOFF'][:5].{Id:SnapshotId,Size:VolumeSize,Created:StartTime}" --output table 2>/dev/null || echo " No old snapshots"
13+
echo ""; echo "Tutorial complete. Read-only — identifies cost optimization opportunities."; rm -rf "$WORK_DIR"

0 commit comments

Comments
 (0)