Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions tuts/107-amazon-efs-gs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# EFS: Create a file system

## Source

https://docs.aws.amazon.com/efs/latest/ug/getting-started.html

## Use case

- **ID**: efs/getting-started
- **Level**: intermediate
- **Core actions**: `elasticfilesystem:CreateFileSystem`, `elasticfilesystem:CreateMountTarget`, `elasticfilesystem:PutLifecycleConfiguration`

## Steps

1. Create an encrypted file system
2. Wait for the file system to be available
3. Describe the file system
4. Create a mount target in the default VPC
5. Wait for the mount target
6. Describe mount targets
7. Set a lifecycle policy

## Resources created

| Resource | Type |
|----------|------|
| `tutorial-efs-<random>` | EFS file system |
| Mount target in default VPC subnet | Mount target |

## Cost

Per-GB pricing. $0.30/GB-month (Standard), $0.025/GB-month (Infrequent Access). An empty file system has no storage cost. Clean up promptly to avoid charges.

## Duration

~114 seconds (mount target creation accounts for most of the wait)

## Related docs

- [Getting started with Amazon EFS](https://docs.aws.amazon.com/efs/latest/ug/getting-started.html)
- [Creating file systems](https://docs.aws.amazon.com/efs/latest/ug/creating-using-create-fs.html)
- [Creating mount targets](https://docs.aws.amazon.com/efs/latest/ug/accessing-fs.html)
- [EFS lifecycle management](https://docs.aws.amazon.com/efs/latest/ug/lifecycle-management-efs.html)
8 changes: 8 additions & 0 deletions tuts/107-amazon-efs-gs/REVISION-HISTORY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Revision History: 107-amazon-efs-gs

## Shell (CLI script)

### 2026-04-14 v1 published
- Type: functional
- Initial version

129 changes: 129 additions & 0 deletions tuts/107-amazon-efs-gs/amazon-efs-gs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Create a file system with Amazon EFS

This tutorial shows you how to create an encrypted Amazon EFS file system, create a mount target in your default VPC, configure a lifecycle policy, and clean up all resources.

## Prerequisites

- AWS CLI configured with credentials and a default region
- A default VPC with at least one subnet in the configured region
- Permissions for `elasticfilesystem:CreateFileSystem`, `elasticfilesystem:DescribeFileSystems`, `elasticfilesystem:CreateMountTarget`, `elasticfilesystem:DescribeMountTargets`, `elasticfilesystem:PutLifecycleConfiguration`, `elasticfilesystem:DescribeLifecycleConfiguration`, `elasticfilesystem:DeleteMountTarget`, `elasticfilesystem:DeleteFileSystem`, `ec2:DescribeVpcs`, `ec2:DescribeSubnets`

## Step 1: Create an encrypted file system

```bash
RANDOM_ID=$(openssl rand -hex 4)
FS_TOKEN="tut-efs-${RANDOM_ID}"

FS_ID=$(aws efs create-file-system --creation-token "$FS_TOKEN" \
--performance-mode generalPurpose \
--throughput-mode bursting \
--encrypted \
--tags Key=Name,Value="tutorial-efs-${RANDOM_ID}" \
--query 'FileSystemId' --output text)
echo "File system ID: $FS_ID"
```

The creation token is an idempotency key — calling `create-file-system` again with the same token returns the existing file system instead of creating a duplicate.

## Step 2: Wait for the file system to be available

```bash
for i in $(seq 1 15); do
STATE=$(aws efs describe-file-systems --file-system-id "$FS_ID" \
--query 'FileSystems[0].LifeCycleState' --output text)
echo "State: $STATE"
[ "$STATE" = "available" ] && break
sleep 5
done
```

## Step 3: Describe the file system

```bash
aws efs describe-file-systems --file-system-id "$FS_ID" \
--query 'FileSystems[0].{Id:FileSystemId,State:LifeCycleState,Encrypted:Encrypted,Performance:PerformanceMode,Size:SizeInBytes.Value}' \
--output table
```

## Step 4: Create a mount target

A mount target provides a network endpoint for mounting the file system. Create one in a subnet of your default VPC.

```bash
VPC_ID=$(aws ec2 describe-vpcs --filters "Name=isDefault,Values=true" \
--query 'Vpcs[0].VpcId' --output text)
SUBNET_ID=$(aws ec2 describe-subnets --filters "Name=vpc-id,Values=$VPC_ID" \
--query 'Subnets[0].SubnetId' --output text)

MT_ID=$(aws efs create-mount-target --file-system-id "$FS_ID" \
--subnet-id "$SUBNET_ID" \
--query 'MountTargetId' --output text)
echo "Mount target: $MT_ID"
```

You need one mount target per Availability Zone. This tutorial creates one for demonstration.

## Step 5: Wait for the mount target

Mount target creation typically takes 60–90 seconds.

```bash
for i in $(seq 1 15); do
MT_STATE=$(aws efs describe-mount-targets --mount-target-id "$MT_ID" \
--query 'MountTargets[0].LifeCycleState' --output text)
echo "State: $MT_STATE"
[ "$MT_STATE" = "available" ] && break
sleep 10
done
```

## Step 6: Describe mount targets

```bash
aws efs describe-mount-targets --file-system-id "$FS_ID" \
--query 'MountTargets[].{Id:MountTargetId,Subnet:SubnetId,State:LifeCycleState,IP:IpAddress}' \
--output table
```

## Step 7: Set a lifecycle policy

Move files not accessed for 30 days to the Infrequent Access (IA) storage class to reduce costs.

```bash
aws efs put-lifecycle-configuration --file-system-id "$FS_ID" \
--lifecycle-policies '[{"TransitionToIA":"AFTER_30_DAYS"}]'

aws efs describe-lifecycle-configuration --file-system-id "$FS_ID" \
--query 'LifecyclePolicies' --output table
```

## Cleanup

Delete mount targets first, then the file system. You must wait for mount targets to finish deleting before the file system can be removed.

```bash
aws efs delete-mount-target --mount-target-id "$MT_ID"

# Wait for mount target deletion
for i in $(seq 1 12); do
MT_COUNT=$(aws efs describe-mount-targets --file-system-id "$FS_ID" \
--query 'MountTargets | length(@)' --output text 2>/dev/null || echo "0")
[ "$MT_COUNT" = "0" ] && break
sleep 10
done

aws efs delete-file-system --file-system-id "$FS_ID"
```

EFS charges per GB stored ($0.30/GB-month for Standard, $0.025/GB-month for IA). An empty file system has no storage cost. The script automates all steps including cleanup:

```bash
bash amazon-efs-gs.sh
```

## Related resources

- [Getting started with Amazon EFS](https://docs.aws.amazon.com/efs/latest/ug/getting-started.html)
- [Creating file systems](https://docs.aws.amazon.com/efs/latest/ug/creating-using-create-fs.html)
- [Creating mount targets](https://docs.aws.amazon.com/efs/latest/ug/accessing-fs.html)
- [EFS lifecycle management](https://docs.aws.amazon.com/efs/latest/ug/lifecycle-management-efs.html)
118 changes: 118 additions & 0 deletions tuts/107-amazon-efs-gs/amazon-efs-gs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#!/bin/bash
# Tutorial: Create an Amazon EFS file system
# Source: https://docs.aws.amazon.com/efs/latest/ug/getting-started.html

WORK_DIR=$(mktemp -d)
LOG_FILE="$WORK_DIR/efs-$(date +%Y%m%d-%H%M%S).log"
exec > >(tee -a "$LOG_FILE") 2>&1

REGION=${AWS_DEFAULT_REGION:-${AWS_REGION:-$(aws configure get region 2>/dev/null)}}
if [ -z "$REGION" ]; then
echo "ERROR: No AWS region configured. Set one with: export AWS_DEFAULT_REGION=us-east-1"
exit 1
fi
export AWS_DEFAULT_REGION="$REGION"
echo "Region: $REGION"

RANDOM_ID=$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 8 | head -n 1)
FS_TOKEN="tut-efs-${RANDOM_ID}"

handle_error() { echo "ERROR on line $1"; trap - ERR; cleanup; exit 1; }
trap 'handle_error $LINENO' ERR

cleanup() {
echo ""
echo "Cleaning up resources..."
if [ -n "$FS_ID" ]; then
# Delete mount targets first
for MT_ID in $(aws efs describe-mount-targets --file-system-id "$FS_ID" \
--query 'MountTargets[].MountTargetId' --output text 2>/dev/null); do
aws efs delete-mount-target --mount-target-id "$MT_ID" 2>/dev/null
echo " Deleted mount target $MT_ID"
done
# Wait for mount targets to be deleted
for i in $(seq 1 12); do
MT_COUNT=$(aws efs describe-mount-targets --file-system-id "$FS_ID" \
--query 'MountTargets | length(@)' --output text 2>/dev/null || echo "0")
[ "$MT_COUNT" = "0" ] && break
sleep 10
done
aws efs delete-file-system --file-system-id "$FS_ID" 2>/dev/null && \
echo " Deleted file system $FS_ID"
fi
rm -rf "$WORK_DIR"
echo "Cleanup complete."
}

# Step 1: Create a file system
echo "Step 1: Creating EFS file system"
FS_ID=$(aws efs create-file-system --creation-token "$FS_TOKEN" \
--performance-mode generalPurpose \
--throughput-mode bursting \
--encrypted \
--tags Key=Name,Value="tutorial-efs-${RANDOM_ID}" \
--query 'FileSystemId' --output text)
echo " File system ID: $FS_ID"

# Step 2: Wait for file system to be available
echo "Step 2: Waiting for file system to be available..."
for i in $(seq 1 15); do
STATE=$(aws efs describe-file-systems --file-system-id "$FS_ID" \
--query 'FileSystems[0].LifeCycleState' --output text)
echo " State: $STATE"
[ "$STATE" = "available" ] && break
sleep 5
done

# Step 3: Describe the file system
echo "Step 3: File system details"
aws efs describe-file-systems --file-system-id "$FS_ID" \
--query 'FileSystems[0].{Id:FileSystemId,State:LifeCycleState,Encrypted:Encrypted,Performance:PerformanceMode,Size:SizeInBytes.Value}' --output table

# Step 4: Create a mount target
echo "Step 4: Creating mount target"
VPC_ID=$(aws ec2 describe-vpcs --filters "Name=isDefault,Values=true" --query 'Vpcs[0].VpcId' --output text)
SUBNET_ID=$(aws ec2 describe-subnets --filters "Name=vpc-id,Values=$VPC_ID" --query 'Subnets[0].SubnetId' --output text)
echo " VPC: $VPC_ID, Subnet: $SUBNET_ID"

MT_ID=$(aws efs create-mount-target --file-system-id "$FS_ID" --subnet-id "$SUBNET_ID" \
--query 'MountTargetId' --output text)
echo " Mount target: $MT_ID"

# Step 5: Wait for mount target
echo "Step 5: Waiting for mount target to be available..."
for i in $(seq 1 15); do
MT_STATE=$(aws efs describe-mount-targets --mount-target-id "$MT_ID" \
--query 'MountTargets[0].LifeCycleState' --output text)
echo " State: $MT_STATE"
[ "$MT_STATE" = "available" ] && break
sleep 10
done

# Step 6: Describe mount targets
echo "Step 6: Mount target details"
aws efs describe-mount-targets --file-system-id "$FS_ID" \
--query 'MountTargets[].{Id:MountTargetId,Subnet:SubnetId,State:LifeCycleState,IP:IpAddress}' --output table

# Step 7: Set lifecycle policy
echo "Step 7: Setting lifecycle policy (move to IA after 30 days)"
aws efs put-lifecycle-configuration --file-system-id "$FS_ID" \
--lifecycle-policies "[{\"TransitionToIA\":\"AFTER_30_DAYS\"}]" > /dev/null
aws efs describe-lifecycle-configuration --file-system-id "$FS_ID" \
--query 'LifecyclePolicies' --output table

echo ""
echo "Tutorial complete."
echo "To mount: sudo mount -t nfs4 $FS_ID.efs.$REGION.amazonaws.com:/ /mnt/efs"
echo ""
echo "Do you want to clean up all resources? (y/n): "
read -r CHOICE
if [[ "$CHOICE" =~ ^[Yy]$ ]]; then
cleanup
else
echo "Resources left running. EFS charges per GB stored."
echo "Manual cleanup:"
echo " aws efs delete-mount-target --mount-target-id $MT_ID"
echo " sleep 60"
echo " aws efs delete-file-system --file-system-id $FS_ID"
fi
38 changes: 38 additions & 0 deletions tuts/127-amazon-glacier-gs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Amazon Glacier Gs

An AWS CLI tutorial that demonstrates Glacier operations.

## Running

```bash
bash amazon-glacier-gs.sh
```

To auto-run with cleanup:

```bash
echo 'y' | bash amazon-glacier-gs.sh
```

## What it does

1. Creating vault: $VAULT_NAME
2. Describing vault
3. Uploading an archive
4. Listing vaults
5. Initiating inventory retrieval

## Resources created

- Vault

The script prompts you to clean up resources when it finishes.

## Cost

Free tier eligible for most operations. Clean up resources after use to avoid charges.

## Related docs

- [AWS CLI glacier reference](https://docs.aws.amazon.com/cli/latest/reference/glacier/index.html)

8 changes: 8 additions & 0 deletions tuts/127-amazon-glacier-gs/REVISION-HISTORY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Revision History: 127-amazon-glacier-gs

## Shell (CLI script)

### 2026-04-14 v1 published
- Type: functional
- Initial version

31 changes: 31 additions & 0 deletions tuts/127-amazon-glacier-gs/amazon-glacier-gs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Amazon Glacier Gs

## Prerequisites

1. AWS CLI installed and configured (`aws configure`)
2. Appropriate IAM permissions for the AWS services used

## Step 1: Creating vault: $VAULT_NAME

The script handles this step automatically. See `amazon-glacier-gs.sh` for the exact CLI commands.

## Step 2: Describing vault

The script handles this step automatically. See `amazon-glacier-gs.sh` for the exact CLI commands.

## Step 3: Uploading an archive

The script handles this step automatically. See `amazon-glacier-gs.sh` for the exact CLI commands.

## Step 4: Listing vaults

The script handles this step automatically. See `amazon-glacier-gs.sh` for the exact CLI commands.

## Step 5: Initiating inventory retrieval

The script handles this step automatically. See `amazon-glacier-gs.sh` for the exact CLI commands.

## Cleanup

The script prompts you to clean up all created resources. If you need to clean up manually, check the script log for the resource names that were created.

Loading
Loading