Skip to content

Commit cc9be10

Browse files
committed
Add management tutorials (batch 18)
1 parent 49f07d9 commit cc9be10

5 files changed

Lines changed: 97 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/sp.log") 2>&1
3+
export AWS_DEFAULT_REGION=us-east-1; echo "Region: us-east-1"
4+
echo "Step 1: Describing savings plans"
5+
aws savingsplans describe-savings-plans --query 'savingsPlans[:5].{Id:savingsPlanId,Type:savingsPlanType,State:state,Commitment:commitment}' --output table 2>/dev/null || echo " No savings plans found"
6+
echo "Step 2: Describing savings plan rates"
7+
aws savingsplans describe-savings-plans-offering-rates --savings-plan-offering-ids [] 2>/dev/null | head -5 || echo " No offering rates (no active plans)"
8+
echo "Step 3: Listing available offerings"
9+
aws savingsplans describe-savings-plans-offerings --query 'searchResults[:3].{Type:planType,Duration:durationSeconds,Currency:currency}' --output table 2>/dev/null || echo " Cannot list offerings"
10+
echo ""; echo "Tutorial complete. No resources created — read-only."
11+
rm -rf "$WORK_DIR"
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/sc.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); PORTFOLIO="tut-portfolio-${RANDOM_ID}"
5+
handle_error() { echo "ERROR on line $1"; trap - ERR; cleanup; exit 1; }; trap 'handle_error $LINENO' ERR
6+
cleanup() { echo ""; echo "Cleaning up..."; [ -n "$PORT_ID" ] && aws servicecatalog delete-portfolio --id "$PORT_ID" 2>/dev/null && echo " Deleted portfolio"; rm -rf "$WORK_DIR"; echo "Done."; }
7+
echo "Step 1: Creating portfolio: $PORTFOLIO"
8+
PORT_ID=$(aws servicecatalog create-portfolio --display-name "$PORTFOLIO" --provider-name "Tutorial" --query 'PortfolioDetail.Id' --output text)
9+
echo " Portfolio ID: $PORT_ID"
10+
echo "Step 2: Describing portfolio"
11+
aws servicecatalog describe-portfolio --id "$PORT_ID" --query 'PortfolioDetail.{Name:DisplayName,Id:Id,Provider:ProviderName,Created:CreatedTime}' --output table
12+
echo "Step 3: Listing portfolios"
13+
aws servicecatalog list-portfolios --query 'PortfolioDetails[?starts_with(DisplayName, `tut-`)].{Name:DisplayName,Id:Id}' --output table
14+
echo ""; echo "Tutorial complete."
15+
echo "Do you want to clean up? (y/n): "; read -r CHOICE; [[ "$CHOICE" =~ ^[Yy]$ ]] && cleanup
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/sso.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 IAM Identity Center instances"
5+
INSTANCE_ARN=$(aws sso-admin list-instances --query 'Instances[0].InstanceArn' --output text 2>/dev/null)
6+
if [ -z "$INSTANCE_ARN" ] || [ "$INSTANCE_ARN" = "None" ]; then echo " No IAM Identity Center instance found. Enable it in the console first."; rm -rf "$WORK_DIR"; exit 0; fi
7+
echo " Instance: $INSTANCE_ARN"
8+
echo "Step 2: Listing permission sets"
9+
aws sso-admin list-permission-sets --instance-arn "$INSTANCE_ARN" --query 'PermissionSets[:5]' --output table 2>/dev/null || echo " No permission sets"
10+
echo "Step 3: Listing accounts for provisioned permission sets"
11+
aws sso-admin list-accounts-for-provisioned-permission-set --instance-arn "$INSTANCE_ARN" --permission-set-arn "$(aws sso-admin list-permission-sets --instance-arn "$INSTANCE_ARN" --query 'PermissionSets[0]' --output text 2>/dev/null)" --query 'AccountIds' --output table 2>/dev/null || echo " No provisioned accounts"
12+
echo ""; echo "Tutorial complete. No resources created — read-only."
13+
rm -rf "$WORK_DIR"
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
WORK_DIR=$(mktemp -d); exec > >(tee -a "$WORK_DIR/cfn.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); STACK_NAME="tut-stack-${RANDOM_ID}"
5+
handle_error() { echo "ERROR on line $1"; trap - ERR; cleanup; exit 1; }; trap 'handle_error $LINENO' ERR
6+
cleanup() { echo ""; echo "Cleaning up..."; aws cloudformation delete-stack --stack-name "$STACK_NAME" 2>/dev/null; aws cloudformation wait stack-delete-complete --stack-name "$STACK_NAME" 2>/dev/null && echo " Stack deleted"; rm -rf "$WORK_DIR"; echo "Done."; }
7+
echo "Step 1: Creating a CloudFormation template"
8+
cat > "$WORK_DIR/template.yaml" << 'EOF'
9+
AWSTemplateFormatVersion: '2010-09-09'
10+
Description: Tutorial stack - creates an SQS queue
11+
Parameters:
12+
QueueName:
13+
Type: String
14+
Default: tutorial-queue
15+
Resources:
16+
TutorialQueue:
17+
Type: AWS::SQS::Queue
18+
Properties:
19+
QueueName: !Ref QueueName
20+
MessageRetentionPeriod: 86400
21+
Outputs:
22+
QueueUrl:
23+
Value: !Ref TutorialQueue
24+
QueueArn:
25+
Value: !GetAtt TutorialQueue.Arn
26+
EOF
27+
echo " Template created"
28+
echo "Step 2: Creating stack: $STACK_NAME"
29+
aws cloudformation create-stack --stack-name "$STACK_NAME" --template-body "file://$WORK_DIR/template.yaml" --parameters "ParameterKey=QueueName,ParameterValue=cfn-tut-${RANDOM_ID}" > /dev/null
30+
echo " Waiting for stack creation..."
31+
aws cloudformation wait stack-create-complete --stack-name "$STACK_NAME"
32+
echo "Step 3: Stack outputs"
33+
aws cloudformation describe-stacks --stack-name "$STACK_NAME" --query 'Stacks[0].Outputs[].{Key:OutputKey,Value:OutputValue}' --output table
34+
echo "Step 4: Listing stack resources"
35+
aws cloudformation list-stack-resources --stack-name "$STACK_NAME" --query 'StackResourceSummaries[].{Type:ResourceType,LogicalId:LogicalResourceId,Status:ResourceStatus}' --output table
36+
echo "Step 5: Stack events"
37+
aws cloudformation describe-stack-events --stack-name "$STACK_NAME" --query 'StackEvents[:5].{Resource:LogicalResourceId,Status:ResourceStatus,Time:Timestamp}' --output table
38+
echo ""; echo "Tutorial complete."
39+
echo "Do you want to clean up? (y/n): "; read -r CHOICE; [[ "$CHOICE" =~ ^[Yy]$ ]] && cleanup
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
WORK_DIR=$(mktemp -d); exec > >(tee -a "$WORK_DIR/cw-math.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); NS="Tutorial/App-${RANDOM_ID}"
5+
cleanup() { echo ""; echo "No cleanup needed — custom metrics expire automatically."; rm -rf "$WORK_DIR"; }
6+
echo "Step 1: Publishing high-resolution metrics"
7+
for i in $(seq 1 10); do
8+
aws cloudwatch put-metric-data --namespace "$NS" --metric-data "[{\"MetricName\":\"Requests\",\"Value\":$((RANDOM % 100 + 50)),\"Unit\":\"Count\",\"StorageResolution\":1},{\"MetricName\":\"Errors\",\"Value\":$((RANDOM % 5)),\"Unit\":\"Count\",\"StorageResolution\":1},{\"MetricName\":\"Latency\",\"Value\":$((RANDOM % 200 + 10)),\"Unit\":\"Milliseconds\"}]"
9+
done
10+
echo " Published 30 data points (10 batches x 3 metrics)"
11+
sleep 3
12+
echo "Step 2: Getting metric statistics"
13+
aws cloudwatch get-metric-statistics --namespace "$NS" --metric-name Requests --start-time "$(date -u -d '5 minutes ago' +%Y-%m-%dT%H:%M:%SZ)" --end-time "$(date -u +%Y-%m-%dT%H:%M:%SZ)" --period 60 --statistics Sum Average Maximum --query 'Datapoints[0].{Sum:Sum,Avg:Average,Max:Maximum}' --output table 2>/dev/null || echo " Metrics not yet available"
14+
echo "Step 3: Using metric math (error rate)"
15+
aws cloudwatch get-metric-data --metric-data-queries '[{"Id":"requests","MetricStat":{"Metric":{"Namespace":"'"$NS"'","MetricName":"Requests"},"Period":60,"Stat":"Sum"},"ReturnData":false},{"Id":"errors","MetricStat":{"Metric":{"Namespace":"'"$NS"'","MetricName":"Errors"},"Period":60,"Stat":"Sum"},"ReturnData":false},{"Id":"error_rate","Expression":"(errors/requests)*100","Label":"Error Rate %","ReturnData":true}]' --start-time "$(date -u -d '5 minutes ago' +%Y-%m-%dT%H:%M:%SZ)" --end-time "$(date -u +%Y-%m-%dT%H:%M:%SZ)" --query 'MetricDataResults[0].{Label:Label,Values:Values}' --output table 2>/dev/null || echo " Math expression result pending"
16+
echo "Step 4: Listing metrics in namespace"
17+
aws cloudwatch list-metrics --namespace "$NS" --query 'Metrics[].{Name:MetricName,Dimensions:Dimensions|length(@)}' --output table
18+
echo ""; echo "Tutorial complete."
19+
cleanup

0 commit comments

Comments
 (0)