Skip to content

Commit 8ade834

Browse files
committed
Address PR #31 review comments
090-comprehend: Replace placeholder 'Your text here' with interesting example text 103-textract: Lead with local file method, S3 as secondary option 103-textract: Script checks for prereq bucket stack before creating one 105-rekognition: Use repo sample image, remove Python image generation step sample-images/: Add placeholder images (to be replaced with real samples)
1 parent 673bf91 commit 8ade834

7 files changed

Lines changed: 48 additions & 65 deletions

File tree

sample-images/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Sample Images
2+
3+
Placeholder images for tutorials that process images (Textract, Rekognition, etc.).
4+
5+
Replace these with real sample images before publishing.
6+
7+
| File | Used by | Description |
8+
|------|---------|-------------|
9+
| sample-document.png | 103-amazon-textract-gs | Document image for text extraction |
10+
| sample-photo.png | 105-amazon-rekognition-gs | Photo for label detection |

sample-images/sample-document.png

1.04 KB
Loading

sample-images/sample-photo.png

1.04 KB
Loading

tuts/090-amazon-comprehend-gs/amazon-comprehend-gs.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ This tutorial shows you how to use the Amazon Comprehend real-time analysis APIs
1010
## Step 1: Detect the dominant language
1111

1212
```bash
13-
aws comprehend detect-dominant-language --text "Your text here" \
13+
aws comprehend detect-dominant-language --text "Amazon Web Services provides cloud computing services that help businesses scale and innovate faster. Customers love the reliability and breadth of services available." \
1414
--query 'Languages[0].{Language:LanguageCode,Confidence:Score}' --output table
1515
```
1616

1717
## Step 2: Detect sentiment
1818

1919
```bash
20-
aws comprehend detect-sentiment --text "Your text here" --language-code en \
20+
aws comprehend detect-sentiment --text "Amazon Web Services provides cloud computing services that help businesses scale and innovate faster. Customers love the reliability and breadth of services available." --language-code en \
2121
--query '{Sentiment:Sentiment,Positive:SentimentScore.Positive,Negative:SentimentScore.Negative}' --output table
2222
```
2323

@@ -26,14 +26,14 @@ aws comprehend detect-sentiment --text "Your text here" --language-code en \
2626
Identifies people, places, organizations, dates, and other entity types.
2727

2828
```bash
29-
aws comprehend detect-entities --text "Your text here" --language-code en \
29+
aws comprehend detect-entities --text "Amazon Web Services provides cloud computing services that help businesses scale and innovate faster. Customers love the reliability and breadth of services available." --language-code en \
3030
--query 'Entities[].{Text:Text,Type:Type,Score:Score}' --output table
3131
```
3232

3333
## Step 4: Detect key phrases
3434

3535
```bash
36-
aws comprehend detect-key-phrases --text "Your text here" --language-code en \
36+
aws comprehend detect-key-phrases --text "Amazon Web Services provides cloud computing services that help businesses scale and innovate faster. Customers love the reliability and breadth of services available." --language-code en \
3737
--query 'KeyPhrases[].{Text:Text,Score:Score}' --output table
3838
```
3939

tuts/103-amazon-textract-gs/amazon-textract-gs.md

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,30 @@ This tutorial shows you how to upload a document image to Amazon S3, use Amazon
88
- Python 3 installed (used to generate a sample PNG image)
99
- Permissions for `s3:CreateBucket`, `s3:PutObject`, `s3:DeleteObject`, `s3:DeleteBucket`, `textract:DetectDocumentText`, and `textract:AnalyzeDocument`
1010

11-
## Step 1: Create a sample document image
11+
## Step 1: Use the sample document image
1212

13-
Generate a minimal PNG image to use as a test document. In practice, you would use a scanned document or photograph containing text.
13+
This tutorial includes a sample document image at `../../sample-images/sample-document.png`. Copy it to your working directory:
14+
15+
```
16+
cp ../../sample-images/sample-document.png sample.png
17+
```
18+
19+
## Step 2: Detect text from local file bytes
20+
21+
Send the document directly as base64-encoded bytes instead of referencing S3.
1422

1523
```bash
16-
WORK_DIR=$(mktemp -d)
17-
18-
python3 -c "
19-
import struct, zlib
20-
w,h=200,50
21-
row=b'\x00'+b'\xff\xff\xff'*w
22-
raw=row*h
23-
comp=zlib.compress(raw)
24-
def ch(t,d):
25-
c=t+d
26-
return struct.pack('>I',len(d))+c+struct.pack('>I',zlib.crc32(c)&0xffffffff)
27-
with open('$WORK_DIR/sample.png','wb') as f:
28-
f.write(b'\x89PNG\r\n\x1a\n')
29-
f.write(ch(b'IHDR',struct.pack('>IIBBBBB',w,h,8,2,0,0,0)))
30-
f.write(ch(b'IDAT',comp))
31-
f.write(ch(b'IEND',b''))
32-
"
33-
echo "Created sample.png (200x50 white image)"
24+
aws textract detect-document-text \
25+
--document '{"Bytes":"'"$(base64 -w0 "$WORK_DIR/sample.png")"'"}' \
26+
--query '{Pages:DocumentMetadata.Pages,BlockCount:Blocks|length(@)}' --output table
3427
```
3528

36-
This creates a blank white PNG. Textract won't find text in it, but it demonstrates the API calls. Replace it with a real document to see text extraction in action.
29+
The `Bytes` option is useful for quick tests or when you don't want to upload to S3 first. The document size limit for synchronous operations is 10 MB.
30+
31+
## Step 3: Upload to S3 (alternative method)
32+
33+
If you want to use S3 instead of local file bytes, upload the image to a bucket. If the tutorial prereq bucket stack is deployed, use that bucket. Otherwise create one.
3734

38-
## Step 2: Upload the document to S3
3935

4036
Create an S3 bucket and upload the sample image.
4137

@@ -52,7 +48,7 @@ echo "Uploaded to s3://$BUCKET_NAME/sample.png"
5248

5349
Textract reads documents directly from S3. For `us-east-1`, omit the `--create-bucket-configuration` parameter.
5450

55-
## Step 3: Detect text in the document
51+
## Step 4: Detect text from S3 in the document
5652

5753
```bash
5854
aws textract detect-document-text \
@@ -62,7 +58,7 @@ aws textract detect-document-text \
6258

6359
`detect-document-text` returns `LINE` and `WORD` blocks. Each block includes the detected text and a confidence score. With the blank sample image, no text lines are returned.
6460

65-
## Step 4: Analyze document for forms and tables
61+
## Step 5: Analyze document for forms and tables
6662

6763
```bash
6864
aws textract analyze-document \
@@ -73,18 +69,6 @@ aws textract analyze-document \
7369

7470
`analyze-document` goes beyond text detection. With `FORMS`, it identifies key-value pairs (like form fields). With `TABLES`, it identifies rows and columns. You can request both features in a single call.
7571

76-
## Step 5: Detect text from local file bytes
77-
78-
Send the document directly as base64-encoded bytes instead of referencing S3.
79-
80-
```bash
81-
aws textract detect-document-text \
82-
--document '{"Bytes":"'"$(base64 -w0 "$WORK_DIR/sample.png")"'"}' \
83-
--query '{Pages:DocumentMetadata.Pages,BlockCount:Blocks|length(@)}' --output table
84-
```
85-
86-
The `Bytes` option is useful for quick tests or when you don't want to upload to S3 first. The document size limit for synchronous operations is 10 MB.
87-
8872
## Cleanup
8973

9074
Delete the S3 bucket and its contents, then remove the temporary directory.

tuts/103-amazon-textract-gs/amazon-textract-gs.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,16 @@ ACCOUNT_ID=$(aws sts get-caller-identity --query 'Account' --output text)
1616
echo "Region: $REGION"
1717

1818
RANDOM_ID=$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 8 | head -n 1)
19-
BUCKET_NAME="textract-tut-${RANDOM_ID}-${ACCOUNT_ID}"
19+
# Check for prereq bucket stack first
20+
PREREQ_BUCKET=$(aws cloudformation describe-stacks --stack-name tutorial-prereqs-bucket --query 'Stacks[0].Outputs[?OutputKey==`BucketName`].OutputValue' --output text 2>/dev/null)
21+
if [ -n "$PREREQ_BUCKET" ] && [ "$PREREQ_BUCKET" != "None" ]; then
22+
BUCKET_NAME="$PREREQ_BUCKET"
23+
BUCKET_IS_PREREQ=true
24+
echo "Using prereq bucket: $BUCKET_NAME"
25+
else
26+
BUCKET_NAME="textract-tut-${RANDOM_ID}-${ACCOUNT_ID}"
27+
BUCKET_IS_PREREQ=false
28+
fi
2029

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

tuts/105-amazon-rekognition-gs/amazon-rekognition-gs.md

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,15 @@ In this tutorial, you use the AWS CLI to analyze images with Amazon Rekognition.
77
## Prerequisites
88

99
- AWS CLI installed and configured with appropriate permissions.
10-
- Python 3 (to generate the sample image).
1110
- An IAM principal with permissions for `rekognition:DetectLabels`, `rekognition:DetectText`, `s3:CreateBucket`, `s3:PutObject`, `s3:DeleteObject`, and `s3:DeleteBucket`.
1211

13-
## Step 1: Create a sample image
12+
## Step 1: Use the sample image
1413

15-
Generate a 100×100 gradient PNG using Python. The gradient gives Rekognition color data to analyze.
14+
This tutorial includes a sample photo at `../../sample-images/sample-photo.png`. Copy it to your working directory:
1615

17-
```bash
18-
python3 -c "
19-
import struct, zlib
20-
w,h=100,100
21-
rows=b''
22-
for y in range(h):
23-
rows+=b'\x00'
24-
for x in range(w):
25-
rows+=bytes([int(x*2.55), int(y*2.55), 128])
26-
comp=zlib.compress(rows)
27-
def ch(t,d):
28-
c=t+d
29-
return struct.pack('>I',len(d))+c+struct.pack('>I',zlib.crc32(c)&0xffffffff)
30-
with open('sample.png','wb') as f:
31-
f.write(b'\x89PNG\r\n\x1a\n')
32-
f.write(ch(b'IHDR',struct.pack('>IIBBBBB',w,h,8,2,0,0,0)))
33-
f.write(ch(b'IDAT',comp))
34-
f.write(ch(b'IEND',b''))
35-
"
3616
```
37-
38-
This creates a minimal valid PNG without any external dependencies.
17+
cp ../../sample-images/sample-photo.png sample.png
18+
```
3919

4020
## Step 2: Upload to S3
4121

0 commit comments

Comments
 (0)