Skip to content

Commit 46502af

Browse files
authored
Merge pull request #47 from aws-samples/feature/shared-bucket
Use shared prereq bucket in tutorials that create S3 buckets
2 parents 8d92079 + a76c0f5 commit 46502af

14 files changed

Lines changed: 118 additions & 9 deletions

File tree

tuts/003-s3-gettingstarted/REVISION-HISTORY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@
1010
- Type: functional
1111
- Remove SDK content from CFN branch (belongs on SDK branches)
1212

13+
14+
### 2026-04-22 v2 shared bucket
15+
- Type: functional
16+
- Script checks for prereq bucket stack before creating its own S3 bucket
17+
- Skips bucket deletion if using shared bucket

tuts/003-s3-gettingstarted/s3-gettingstarted.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,17 @@ fi
2020
# ============================================================================
2121

2222
UNIQUE_ID=$(cat /dev/urandom | tr -dc 'a-f0-9' | fold -w 12 | head -n 1)
23-
BUCKET_NAME="s3api-${UNIQUE_ID}"
23+
# Check for shared prereq bucket
24+
PREREQ_BUCKET=$(aws cloudformation describe-stacks --stack-name tutorial-prereqs-bucket \
25+
--query 'Stacks[0].Outputs[?OutputKey==`BucketName`].OutputValue' --output text 2>/dev/null)
26+
if [ -n "$PREREQ_BUCKET" ] && [ "$PREREQ_BUCKET" != "None" ]; then
27+
BUCKET_NAME="$PREREQ_BUCKET"
28+
BUCKET_IS_SHARED=true
29+
echo "Using shared bucket: $BUCKET_NAME"
30+
else
31+
BUCKET_IS_SHARED=false
32+
BUCKET_NAME="s3api-${UNIQUE_ID}"
33+
fi
2434

2535
TEMP_DIR=$(mktemp -d)
2636
LOG_FILE="${TEMP_DIR}/s3-gettingstarted.log"
@@ -83,7 +93,9 @@ cleanup() {
8393
fi
8494

8595
echo "Deleting bucket: ${BUCKET_NAME}"
86-
aws s3api delete-bucket --bucket "$BUCKET_NAME" 2>&1 || echo "WARNING: Failed to delete bucket ${BUCKET_NAME}"
96+
if [ "$BUCKET_IS_SHARED" = "false" ]; then
97+
aws s3api delete-bucket --bucket "$BUCKET_NAME" 2>&1 || echo "WARNING: Failed to delete bucket ${BUCKET_NAME}"
98+
fi
8799

88100
echo ""
89101
echo "Cleaning up temp directory: ${TEMP_DIR}"

tuts/005-cloudfront-gettingstarted/REVISION-HISTORY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@
1010
- Type: functional
1111
- Remove SDK content from CFN branch (belongs on SDK branches)
1212

13+
14+
### 2026-04-22 v2 shared bucket
15+
- Type: functional
16+
- Script checks for prereq bucket stack before creating its own S3 bucket
17+
- Skips bucket deletion if using shared bucket

tuts/005-cloudfront-gettingstarted/cloudfront-gettingstarted.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,17 @@ cleanup() {
106106

107107
# Generate a random identifier for the bucket name
108108
RANDOM_ID=$(openssl rand -hex 6)
109-
BUCKET_NAME="cloudfront-${RANDOM_ID}"
109+
# Check for shared prereq bucket
110+
PREREQ_BUCKET=$(aws cloudformation describe-stacks --stack-name tutorial-prereqs-bucket \
111+
--query 'Stacks[0].Outputs[?OutputKey==`BucketName`].OutputValue' --output text 2>/dev/null)
112+
if [ -n "$PREREQ_BUCKET" ] && [ "$PREREQ_BUCKET" != "None" ]; then
113+
BUCKET_NAME="$PREREQ_BUCKET"
114+
BUCKET_IS_SHARED=true
115+
echo "Using shared bucket: $BUCKET_NAME"
116+
else
117+
BUCKET_IS_SHARED=false
118+
BUCKET_NAME="cloudfront-${RANDOM_ID}"
119+
fi
110120
echo "Using bucket name: $BUCKET_NAME"
111121

112122
# Create a temporary directory for content

tuts/028-sagemaker-featurestore/REVISION-HISTORY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@
1010
- Type: functional
1111
- unordered list bullets and trailing whitespace
1212

13+
14+
### 2026-04-22 v2 shared bucket
15+
- Type: functional
16+
- Script checks for prereq bucket stack before creating its own S3 bucket
17+
- Skips bucket deletion if using shared bucket

tuts/028-sagemaker-featurestore/sagemaker-featurestore.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,17 @@ if [ -z "$REGION" ]; then
201201
else
202202
echo "Using region: $REGION"
203203
fi
204-
S3_BUCKET_NAME="sagemaker-featurestore-${RANDOM_ID}-${ACCOUNT_ID}"
204+
# Check for shared prereq bucket
205+
PREREQ_BUCKET=$(aws cloudformation describe-stacks --stack-name tutorial-prereqs-bucket \
206+
--query 'Stacks[0].Outputs[?OutputKey==`BucketName`].OutputValue' --output text 2>/dev/null)
207+
if [ -n "$PREREQ_BUCKET" ] && [ "$PREREQ_BUCKET" != "None" ]; then
208+
S3_BUCKET_NAME="$PREREQ_BUCKET"
209+
BUCKET_IS_SHARED=true
210+
echo "Using shared bucket: $S3_BUCKET_NAME"
211+
else
212+
BUCKET_IS_SHARED=false
213+
S3_BUCKET_NAME="sagemaker-featurestore-${RANDOM_ID}-${ACCOUNT_ID}"
214+
fi
205215
PREFIX="featurestore-tutorial"
206216
CURRENT_TIME=$(date +%s)
207217

tuts/037-emr-gs/REVISION-HISTORY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@
1010
- Type: functional
1111
- security and consistency updates
1212

13+
14+
### 2026-04-22 v2 shared bucket
15+
- Type: functional
16+
- Script checks for prereq bucket stack before creating its own S3 bucket
17+
- Skips bucket deletion if using shared bucket

tuts/037-emr-gs/emr-gs.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,17 @@ cleanup() {
6363

6464
# Generate a random identifier for S3 bucket
6565
RANDOM_ID=$(openssl rand -hex 6)
66-
BUCKET_NAME="emr${RANDOM_ID}"
66+
# Check for shared prereq bucket
67+
PREREQ_BUCKET=$(aws cloudformation describe-stacks --stack-name tutorial-prereqs-bucket \
68+
--query 'Stacks[0].Outputs[?OutputKey==`BucketName`].OutputValue' --output text 2>/dev/null)
69+
if [ -n "$PREREQ_BUCKET" ] && [ "$PREREQ_BUCKET" != "None" ]; then
70+
BUCKET_NAME="$PREREQ_BUCKET"
71+
BUCKET_IS_SHARED=true
72+
echo "Using shared bucket: $BUCKET_NAME"
73+
else
74+
BUCKET_IS_SHARED=false
75+
BUCKET_NAME="emr${RANDOM_ID}"
76+
fi
6777
echo "Using bucket name: $BUCKET_NAME"
6878

6979
# Create S3 bucket

tuts/053-aws-config-gs/REVISION-HISTORY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@
1010
- Type: functional
1111
- unordered list bullets and trailing whitespace
1212

13+
14+
### 2026-04-22 v2 shared bucket
15+
- Type: functional
16+
- Script checks for prereq bucket stack before creating its own S3 bucket
17+
- Skips bucket deletion if using shared bucket

tuts/053-aws-config-gs/aws-config-gs.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ cleanup_resources() {
7878
aws s3 rm "s3://$S3_BUCKET_NAME" --recursive 2>/dev/null || true
7979

8080
echo "Deleting S3 bucket..."
81-
aws s3api delete-bucket --bucket "$S3_BUCKET_NAME" 2>/dev/null || true
81+
if [ "$BUCKET_IS_SHARED" = "false" ]; then
82+
aws s3api delete-bucket --bucket "$S3_BUCKET_NAME" 2>/dev/null || true
83+
fi
8284
fi
8385
}
8486

@@ -118,7 +120,17 @@ RANDOM_ID=$(generate_random_id)
118120
echo "Generated random identifier: $RANDOM_ID"
119121

120122
# Step 1: Create an S3 bucket
121-
S3_BUCKET_NAME="configservice-${RANDOM_ID}"
123+
# Check for shared prereq bucket
124+
PREREQ_BUCKET=$(aws cloudformation describe-stacks --stack-name tutorial-prereqs-bucket \
125+
--query 'Stacks[0].Outputs[?OutputKey==`BucketName`].OutputValue' --output text 2>/dev/null)
126+
if [ -n "$PREREQ_BUCKET" ] && [ "$PREREQ_BUCKET" != "None" ]; then
127+
S3_BUCKET_NAME="$PREREQ_BUCKET"
128+
BUCKET_IS_SHARED=true
129+
echo "Using shared bucket: $S3_BUCKET_NAME"
130+
else
131+
BUCKET_IS_SHARED=false
132+
S3_BUCKET_NAME="configservice-${RANDOM_ID}"
133+
fi
122134
echo "Creating S3 bucket: $S3_BUCKET_NAME"
123135

124136
# Get the current region

0 commit comments

Comments
 (0)