Skip to content

Commit eb150af

Browse files
committed
Add CFN interact scripts and SDK/CFN sections to READMEs
- *-cfn.sh scripts run interactive steps against CFN-created resources - Each command shown with $ prefix and resolved variables - READMEs now include SDK examples and CloudFormation sections
1 parent ddfd3df commit eb150af

20 files changed

Lines changed: 1020 additions & 9 deletions

File tree

tuts/001-lightsail-gs/README.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,53 @@ The script creates the following AWS resources in order:
1212
- Lightsail disk (8 GB block storage disk)
1313
- Lightsail instance snapshot (backup of the instance)
1414

15-
The script prompts you to clean up resources when you run it, including if there's an error part way through. If you need to clean up resources later, you can use the script log as a reference point for which resources were created.
15+
The script prompts you to clean up resources when you run it, including if there's an error part way through. If you need to clean up resources later, you can use the script log as a reference point for which resources were created.
16+
17+
18+
## SDK examples
19+
20+
This tutorial is also available as SDK examples in Python and JavaScript (with scaffolds for 9 additional languages). Each implements the same scenario with wrapper classes, a scenario orchestrator, and unit tests.
21+
22+
### Run with Python
23+
24+
```bash
25+
cd tuts/001-lightsail-gs/python
26+
python3 -m venv .venv && source .venv/bin/activate
27+
pip install -r requirements.txt
28+
python3 scenario_getting_started.py
29+
```
30+
31+
### Run with JavaScript
32+
33+
```bash
34+
cd tuts/001-lightsail-gs/javascript
35+
npm install
36+
node scenarios/getting-started.js
37+
```
38+
39+
See the `python/` and `javascript/` directories for source code and tests.
40+
## CloudFormation
41+
42+
This tutorial includes a CloudFormation template that creates the same resources as the CLI script.
43+
44+
**Resources created:** Lightsail instance and disk
45+
46+
### Deploy with CloudFormation
47+
48+
```bash
49+
./deploy.sh 001-lightsail-gs
50+
```
51+
52+
### Run the interactive steps
53+
54+
Once deployed, run the interactive tutorial steps against the CloudFormation-created resources. Each command is displayed with resolved values so you can run them individually.
55+
56+
```bash
57+
bash tuts/001-lightsail-gs/lightsail-gs-cfn.sh
58+
```
59+
60+
### Clean up
61+
62+
```bash
63+
./cleanup.sh 001-lightsail-gs
64+
```
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
# Run the interactive tutorial steps against resources created by CloudFormation.
3+
# If the stack does not exist, offers to deploy it first.
4+
set -eo pipefail
5+
6+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
7+
REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
8+
TUT_DIR="$(basename "$SCRIPT_DIR")"
9+
STACK_NAME="tutorial-$(echo "$TUT_DIR" | sed 's/^[0-9]*-//')"
10+
11+
get_output() { aws cloudformation describe-stacks --stack-name "$STACK_NAME" --query "Stacks[0].Outputs[?OutputKey==\`$1\`].OutputValue" --output text 2>/dev/null; }
12+
13+
run_cmd() {
14+
echo ""
15+
echo "$ $@"
16+
eval "$@"
17+
}
18+
19+
# Check if stack exists, offer to create
20+
STATUS=$(aws cloudformation describe-stacks --stack-name "$STACK_NAME" --query 'Stacks[0].StackStatus' --output text 2>/dev/null || echo "NONE")
21+
if [ "$STATUS" = "NONE" ] || [ "$STATUS" = "DELETE_COMPLETE" ]; then
22+
echo "Stack $STACK_NAME does not exist."
23+
read -rp "Deploy it now? (y/n): " CHOICE
24+
if [[ "$CHOICE" =~ ^[Yy]$ ]]; then
25+
"$REPO_ROOT/deploy.sh" "$TUT_DIR"
26+
else
27+
echo "Cannot proceed without the stack. Deploy with: ./deploy.sh $TUT_DIR"
28+
exit 1
29+
fi
30+
fi
31+
echo "Stack: $STACK_NAME ($STATUS)"
32+
33+
INSTANCE=$(get_output InstanceName)
34+
DISK=$(get_output DiskName)
35+
echo "Instance: $INSTANCE"
36+
echo "Disk: $DISK"
37+
38+
echo ""
39+
echo "--- Step 1: Get instance state ---"
40+
run_cmd aws lightsail get-instance-state --instance-name "$INSTANCE"
41+
42+
echo ""
43+
echo "--- Step 2: Get instance details ---"
44+
run_cmd aws lightsail get-instance --instance-name "$INSTANCE" --query "'instance.{name:name,blueprint:blueprintId,bundle:bundleId,state:state.name,ip:publicIpAddress}'" --output table
45+
46+
echo ""
47+
echo "--- Step 3: Create a snapshot ---"
48+
SNAP_NAME="${INSTANCE}-snapshot"
49+
run_cmd aws lightsail create-instance-snapshot --instance-name "$INSTANCE" --instance-snapshot-name "$SNAP_NAME"
50+
51+
echo ""
52+
echo "--- Step 4: Delete the snapshot ---"
53+
sleep 10
54+
run_cmd aws lightsail delete-instance-snapshot --instance-snapshot-name "$SNAP_NAME"
55+
56+
echo ""
57+
echo "Interactive steps complete."
58+
echo "To delete stack: ./cleanup.sh $TUT_DIR"

tuts/002-vpc-gs/README.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,53 @@ The script creates the following AWS resources in order:
2525
- EC2 security group (web server security group allowing HTTP/HTTPS)
2626
- EC2 security group (database security group allowing MySQL from web servers)
2727

28-
The script prompts you to clean up resources when you run it, including if there's an error part way through. If you need to clean up resources later, you can use the script log as a reference point for which resources were created.
28+
The script prompts you to clean up resources when you run it, including if there's an error part way through. If you need to clean up resources later, you can use the script log as a reference point for which resources were created.
29+
30+
31+
## SDK examples
32+
33+
This tutorial is also available as SDK examples in Python and JavaScript (with scaffolds for 9 additional languages). Each implements the same scenario with wrapper classes, a scenario orchestrator, and unit tests.
34+
35+
### Run with Python
36+
37+
```bash
38+
cd tuts/002-vpc-gs/python
39+
python3 -m venv .venv && source .venv/bin/activate
40+
pip install -r requirements.txt
41+
python3 scenario_getting_started.py
42+
```
43+
44+
### Run with JavaScript
45+
46+
```bash
47+
cd tuts/002-vpc-gs/javascript
48+
npm install
49+
node scenarios/getting-started.js
50+
```
51+
52+
See the `python/` and `javascript/` directories for source code and tests.
53+
## CloudFormation
54+
55+
This tutorial includes a CloudFormation template that creates the same resources as the CLI script.
56+
57+
**Resources created:** VPC with public subnet and EC2 instance
58+
59+
### Deploy with CloudFormation
60+
61+
```bash
62+
./deploy.sh 002-vpc-gs
63+
```
64+
65+
### Run the interactive steps
66+
67+
Once deployed, run the interactive tutorial steps against the CloudFormation-created resources. Each command is displayed with resolved values so you can run them individually.
68+
69+
```bash
70+
bash tuts/002-vpc-gs/vpc-gs-cfn.sh
71+
```
72+
73+
### Clean up
74+
75+
```bash
76+
./cleanup.sh 002-vpc-gs
77+
```

tuts/002-vpc-gs/vpc-gs-cfn.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
# Run the interactive tutorial steps against resources created by CloudFormation.
3+
# If the stack does not exist, offers to deploy it first.
4+
set -eo pipefail
5+
6+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
7+
REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
8+
TUT_DIR="$(basename "$SCRIPT_DIR")"
9+
STACK_NAME="tutorial-$(echo "$TUT_DIR" | sed 's/^[0-9]*-//')"
10+
11+
get_output() { aws cloudformation describe-stacks --stack-name "$STACK_NAME" --query "Stacks[0].Outputs[?OutputKey==\`$1\`].OutputValue" --output text 2>/dev/null; }
12+
13+
run_cmd() {
14+
echo ""
15+
echo "$ $@"
16+
eval "$@"
17+
}
18+
19+
# Check if stack exists, offer to create
20+
STATUS=$(aws cloudformation describe-stacks --stack-name "$STACK_NAME" --query 'Stacks[0].StackStatus' --output text 2>/dev/null || echo "NONE")
21+
if [ "$STATUS" = "NONE" ] || [ "$STATUS" = "DELETE_COMPLETE" ]; then
22+
echo "Stack $STACK_NAME does not exist."
23+
read -rp "Deploy it now? (y/n): " CHOICE
24+
if [[ "$CHOICE" =~ ^[Yy]$ ]]; then
25+
"$REPO_ROOT/deploy.sh" "$TUT_DIR"
26+
else
27+
echo "Cannot proceed without the stack. Deploy with: ./deploy.sh $TUT_DIR"
28+
exit 1
29+
fi
30+
fi
31+
echo "Stack: $STACK_NAME ($STATUS)"
32+
33+
VPC_ID=$(get_output VpcId)
34+
INSTANCE_ID=$(get_output InstanceId)
35+
PUBLIC_IP=$(get_output PublicIp)
36+
echo "VPC: $VPC_ID | Instance: $INSTANCE_ID | IP: $PUBLIC_IP"
37+
38+
echo ""
39+
echo "--- Step 1: Describe the VPC ---"
40+
run_cmd aws ec2 describe-vpcs --vpc-ids "$VPC_ID" --query "'Vpcs[0].{VpcId:VpcId,CIDR:CidrBlock,State:State}'" --output table
41+
42+
echo ""
43+
echo "--- Step 2: List subnets ---"
44+
run_cmd aws ec2 describe-subnets --filters "Name=vpc-id,Values=$VPC_ID" --query "'Subnets[].{Id:SubnetId,CIDR:CidrBlock,AZ:AvailabilityZone}'" --output table
45+
46+
echo ""
47+
echo "--- Step 3: Check instance status ---"
48+
run_cmd aws ec2 describe-instances --instance-ids "$INSTANCE_ID" --query "'Reservations[0].Instances[0].{State:State.Name,Type:InstanceType,IP:PublicIpAddress}'" --output table
49+
50+
echo ""
51+
echo "Interactive steps complete."
52+
echo "To delete stack: ./cleanup.sh $TUT_DIR"

tuts/003-s3-gettingstarted/README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,55 @@ Free tier eligible. No charges expected for a few objects.
5757

5858
---
5959

60+
61+
62+
## SDK examples
63+
64+
This tutorial is also available as SDK examples in Python and JavaScript (with scaffolds for 9 additional languages). Each implements the same scenario with wrapper classes, a scenario orchestrator, and unit tests.
65+
66+
### Run with Python
67+
68+
```bash
69+
cd tuts/003-s3-gettingstarted/python
70+
python3 -m venv .venv && source .venv/bin/activate
71+
pip install -r requirements.txt
72+
python3 scenario_getting_started.py
73+
```
74+
75+
### Run with JavaScript
76+
77+
```bash
78+
cd tuts/003-s3-gettingstarted/javascript
79+
npm install
80+
node scenarios/getting-started.js
81+
```
82+
83+
See the `python/` and `javascript/` directories for source code and tests.
84+
## CloudFormation
85+
86+
This tutorial includes a CloudFormation template that creates the same resources as the CLI script.
87+
88+
**Resources created:** S3 bucket (uses shared prereq bucket)
89+
90+
### Deploy with CloudFormation
91+
92+
```bash
93+
./deploy.sh 003-s3-gettingstarted
94+
```
95+
96+
### Run the interactive steps
97+
98+
Once deployed, run the interactive tutorial steps against the CloudFormation-created resources. Each command is displayed with resolved values so you can run them individually.
99+
100+
```bash
101+
bash tuts/003-s3-gettingstarted/s3-gettingstarted-cfn.sh
102+
```
103+
104+
### Clean up
105+
106+
```bash
107+
./cleanup.sh 003-s3-gettingstarted
108+
```
60109
## Appendix: Generation details
61110

62111
| Field | Value |
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/bin/bash
2+
# Run the interactive tutorial steps against resources created by CloudFormation.
3+
# If the stack does not exist, offers to deploy it first.
4+
set -eo pipefail
5+
6+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
7+
REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
8+
TUT_DIR="$(basename "$SCRIPT_DIR")"
9+
STACK_NAME="tutorial-$(echo "$TUT_DIR" | sed 's/^[0-9]*-//')"
10+
11+
get_output() { aws cloudformation describe-stacks --stack-name "$STACK_NAME" --query "Stacks[0].Outputs[?OutputKey==\`$1\`].OutputValue" --output text 2>/dev/null; }
12+
13+
run_cmd() {
14+
echo ""
15+
echo "$ $@"
16+
eval "$@"
17+
}
18+
19+
# Check if stack exists, offer to create
20+
STATUS=$(aws cloudformation describe-stacks --stack-name "$STACK_NAME" --query 'Stacks[0].StackStatus' --output text 2>/dev/null || echo "NONE")
21+
if [ "$STATUS" = "NONE" ] || [ "$STATUS" = "DELETE_COMPLETE" ]; then
22+
echo "Stack $STACK_NAME does not exist."
23+
read -rp "Deploy it now? (y/n): " CHOICE
24+
if [[ "$CHOICE" =~ ^[Yy]$ ]]; then
25+
"$REPO_ROOT/deploy.sh" "$TUT_DIR"
26+
else
27+
echo "Cannot proceed without the stack. Deploy with: ./deploy.sh $TUT_DIR"
28+
exit 1
29+
fi
30+
fi
31+
echo "Stack: $STACK_NAME ($STATUS)"
32+
33+
BUCKET=$(get_output BucketName)
34+
echo "Bucket: $BUCKET"
35+
36+
echo ""
37+
echo "--- Step 1: Upload an object ---"
38+
echo "Hello from the S3 tutorial" > /tmp/s3-tut-test.txt
39+
run_cmd aws s3 cp /tmp/s3-tut-test.txt "s3://$BUCKET/tutorial/hello.txt"
40+
41+
echo ""
42+
echo "--- Step 2: List objects ---"
43+
run_cmd aws s3api list-objects-v2 --bucket "$BUCKET" --prefix tutorial/ --query "'Contents[].{Key:Key,Size:Size}'" --output table
44+
45+
echo ""
46+
echo "--- Step 3: Download the object ---"
47+
run_cmd aws s3 cp "s3://$BUCKET/tutorial/hello.txt" /tmp/s3-tut-download.txt
48+
echo "Content: $(cat /tmp/s3-tut-download.txt)"
49+
50+
echo ""
51+
echo "--- Step 4: Copy the object ---"
52+
run_cmd aws s3 cp "s3://$BUCKET/tutorial/hello.txt" "s3://$BUCKET/tutorial/backup/hello.txt"
53+
54+
echo ""
55+
echo "--- Step 5: List all objects ---"
56+
run_cmd aws s3api list-objects-v2 --bucket "$BUCKET" --prefix tutorial/ --query "'Contents[].Key'" --output table
57+
58+
echo ""
59+
echo "--- Step 6: Clean up tutorial objects ---"
60+
run_cmd aws s3 rm "s3://$BUCKET/tutorial/" --recursive
61+
rm -f /tmp/s3-tut-test.txt /tmp/s3-tut-download.txt
62+
echo "Bucket remains for other tutorials."

tuts/004-cloudmap-custom-attributes/README.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,53 @@ The script creates the following AWS resources in order:
2626
- Service Discovery instance (e)
2727
- Service Discovery instance (f)
2828

29-
The script prompts you to clean up resources when you run it, including if there's an error part way through. If you need to clean up resources later, you can use the script log as a reference point for which resources were created.
29+
The script prompts you to clean up resources when you run it, including if there's an error part way through. If you need to clean up resources later, you can use the script log as a reference point for which resources were created.
30+
31+
32+
## SDK examples
33+
34+
This tutorial is also available as SDK examples in Python and JavaScript (with scaffolds for 9 additional languages). Each implements the same scenario with wrapper classes, a scenario orchestrator, and unit tests.
35+
36+
### Run with Python
37+
38+
```bash
39+
cd tuts/004-cloudmap-custom-attributes/python
40+
python3 -m venv .venv && source .venv/bin/activate
41+
pip install -r requirements.txt
42+
python3 scenario_getting_started.py
43+
```
44+
45+
### Run with JavaScript
46+
47+
```bash
48+
cd tuts/004-cloudmap-custom-attributes/javascript
49+
npm install
50+
node scenarios/getting-started.js
51+
```
52+
53+
See the `python/` and `javascript/` directories for source code and tests.
54+
## CloudFormation
55+
56+
This tutorial includes a CloudFormation template that creates the same resources as the CLI script.
57+
58+
**Resources created:** Cloud Map namespace, DynamoDB table, Lambda function
59+
60+
### Deploy with CloudFormation
61+
62+
```bash
63+
./deploy.sh 004-cloudmap-custom-attributes
64+
```
65+
66+
### Run the interactive steps
67+
68+
Once deployed, run the interactive tutorial steps against the CloudFormation-created resources. Each command is displayed with resolved values so you can run them individually.
69+
70+
```bash
71+
bash tuts/004-cloudmap-custom-attributes/cloudmap-custom-attributes-cfn.sh
72+
```
73+
74+
### Clean up
75+
76+
```bash
77+
./cleanup.sh 004-cloudmap-custom-attributes
78+
```

0 commit comments

Comments
 (0)