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
59 changes: 59 additions & 0 deletions tuts/090-amazon-comprehend-gs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Comprehend: Detect sentiment, entities, and key phrases

Analyze text using Amazon Comprehend's real-time APIs for language detection, sentiment analysis, entity recognition, key phrase extraction, and PII detection.

## Source

https://docs.aws.amazon.com/comprehend/latest/dg/get-started-api.html

## Use case

- ID: comprehend/getting-started
- Phase: create
- Complexity: beginner
- Core actions: comprehend:DetectSentiment, comprehend:DetectEntities, comprehend:DetectKeyPhrases

## What it does

1. Detects the dominant language of sample text
2. Analyzes sentiment (positive, negative, neutral, mixed)
3. Extracts named entities (people, organizations, dates)
4. Extracts key phrases
5. Detects PII entities (names, emails, phone numbers)

## Running

```bash
bash amazon-comprehend-gs.sh
```

## Resources created

None. Comprehend is a stateless API.

## Estimated time

- Run: ~5 seconds

## Cost

Comprehend pricing is per unit (100 characters). This tutorial analyzes ~500 characters, costing less than $0.01.

## Related docs

- [Real-time analysis with Amazon Comprehend](https://docs.aws.amazon.com/comprehend/latest/dg/get-started-api.html)
- [Sentiment analysis](https://docs.aws.amazon.com/comprehend/latest/dg/how-sentiment.html)
- [Entity recognition](https://docs.aws.amazon.com/comprehend/latest/dg/how-entities.html)
- [PII detection](https://docs.aws.amazon.com/comprehend/latest/dg/how-pii.html)

---

## Appendix: Generation details

| Field | Value |
|-------|-------|
| Generation date | 2026-04-14 |
| Source script | New, 57 lines |
| Script test result | EXIT 0, 5s, 5 steps, stateless API |
| Issues encountered | None — stateless API, no resource management needed |
| Iterations | v1 (direct to publish) |
57 changes: 57 additions & 0 deletions tuts/090-amazon-comprehend-gs/amazon-comprehend-gs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Detect sentiment, entities, and key phrases with Amazon Comprehend

This tutorial shows you how to use the Amazon Comprehend real-time analysis APIs to detect the dominant language, sentiment, entities, key phrases, and PII in text.

## Prerequisites

- AWS CLI configured with credentials and a default region
- Permissions to call Amazon Comprehend APIs

## Step 1: Detect the dominant language

```bash
aws comprehend detect-dominant-language --text "Your text here" \
--query 'Languages[0].{Language:LanguageCode,Confidence:Score}' --output table
```

## Step 2: Detect sentiment

```bash
aws comprehend detect-sentiment --text "Your text here" --language-code en \
--query '{Sentiment:Sentiment,Positive:SentimentScore.Positive,Negative:SentimentScore.Negative}' --output table
```

## Step 3: Detect entities

Identifies people, places, organizations, dates, and other entity types.

```bash
aws comprehend detect-entities --text "Your text here" --language-code en \
--query 'Entities[].{Text:Text,Type:Type,Score:Score}' --output table
```

## Step 4: Detect key phrases

```bash
aws comprehend detect-key-phrases --text "Your text here" --language-code en \
--query 'KeyPhrases[].{Text:Text,Score:Score}' --output table
```

## Step 5: Detect PII entities

Identifies personally identifiable information such as names, email addresses, phone numbers, and account numbers.

```bash
aws comprehend detect-pii-entities --text "Contact Jane at jane@example.com" --language-code en \
--query 'Entities[].{Type:Type,Score:Score}' --output table
```

## Cleanup

No cleanup needed. Comprehend is a stateless API — no resources are created.

The script automates all steps:

```bash
bash amazon-comprehend-gs.sh
```
57 changes: 57 additions & 0 deletions tuts/090-amazon-comprehend-gs/amazon-comprehend-gs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash
# Tutorial: Detect sentiment, entities, and key phrases with Amazon Comprehend
# Source: https://docs.aws.amazon.com/comprehend/latest/dg/get-started-api.html

WORK_DIR=$(mktemp -d)
LOG_FILE="$WORK_DIR/comprehend-$(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"

TEXT="Amazon Comprehend is a natural language processing service that uses machine learning to find insights and relationships in text. The service can identify the language of the text, extract key phrases, places, people, brands, or events, and understand how positive or negative the text is."

echo ""
echo "Sample text:"
echo " $TEXT"
echo ""

# Step 1: Detect dominant language
echo "Step 1: Detecting dominant language"
aws comprehend detect-dominant-language --text "$TEXT" \
--query 'Languages[0].{Language:LanguageCode,Confidence:Score}' --output table

# Step 2: Detect sentiment
echo ""
echo "Step 2: Detecting sentiment"
aws comprehend detect-sentiment --text "$TEXT" --language-code en \
--query '{Sentiment:Sentiment,Positive:SentimentScore.Positive,Negative:SentimentScore.Negative,Neutral:SentimentScore.Neutral}' --output table

# Step 3: Detect entities
echo ""
echo "Step 3: Detecting entities"
aws comprehend detect-entities --text "$TEXT" --language-code en \
--query 'Entities[].{Text:Text,Type:Type,Score:Score}' --output table

# Step 4: Detect key phrases
echo ""
echo "Step 4: Detecting key phrases"
aws comprehend detect-key-phrases --text "$TEXT" --language-code en \
--query 'KeyPhrases[].{Text:Text,Score:Score}' --output table

# Step 5: Detect PII entities
echo ""
echo "Step 5: Detecting PII entities"
PII_TEXT="Please contact Jane Smith at jane.smith@example.com or call 555-0123. Her account number is 1234567890."
echo " PII sample: $PII_TEXT"
aws comprehend detect-pii-entities --text "$PII_TEXT" --language-code en \
--query 'Entities[].{Type:Type,Score:Score}' --output table

echo ""
echo "Tutorial complete. No resources were created — Comprehend is a stateless API."
rm -rf "$WORK_DIR"
59 changes: 59 additions & 0 deletions tuts/091-amazon-translate-gs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Translate: Translate text between languages

Translate text between languages using Amazon Translate, with auto-detection of the source language.

## Source

https://docs.aws.amazon.com/translate/latest/dg/get-started.html

## Use case

- ID: translate/getting-started
- Phase: create
- Complexity: beginner
- Core actions: translate:TranslateText, translate:ListLanguages

## What it does

1. Translates English text to Spanish
2. Translates English text to French
3. Translates English text to Japanese
4. Auto-detects source language (German → English)
5. Lists supported languages

## Running

```bash
bash amazon-translate-gs.sh
```

## Resources created

None. Translate is a stateless API.

## Estimated time

- Run: ~5 seconds

## Cost

Translate pricing is per character. This tutorial translates ~600 characters, costing less than $0.01.

## Related docs

- [Getting started with Amazon Translate](https://docs.aws.amazon.com/translate/latest/dg/get-started.html)
- [Translating text using the API](https://docs.aws.amazon.com/translate/latest/dg/get-started-api.html)
- [Supported languages](https://docs.aws.amazon.com/translate/latest/dg/what-is-languages.html)
- [Automatic source language detection](https://docs.aws.amazon.com/translate/latest/dg/auto-detect.html)

---

## Appendix: Generation details

| Field | Value |
|-------|-------|
| Generation date | 2026-04-14 |
| Source script | New, 60 lines |
| Script test result | EXIT 0, 5s, 5 steps, stateless API |
| Issues encountered | None — stateless API, no resource management needed |
| Iterations | v1 (direct to publish) |
63 changes: 63 additions & 0 deletions tuts/091-amazon-translate-gs/amazon-translate-gs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Translate text between languages with Amazon Translate

This tutorial shows you how to use Amazon Translate to translate text between languages, auto-detect the source language, and list supported languages.

## Prerequisites

- AWS CLI configured with credentials and a default region
- Permissions to call Amazon Translate APIs

## Step 1: Translate English to Spanish

```bash
aws translate translate-text \
--text "Your text here" \
--source-language-code en --target-language-code es \
--query 'TranslatedText' --output text
```

## Step 2: Translate English to French

```bash
aws translate translate-text \
--text "Your text here" \
--source-language-code en --target-language-code fr \
--query 'TranslatedText' --output text
```

## Step 3: Translate English to Japanese

```bash
aws translate translate-text \
--text "Your text here" \
--source-language-code en --target-language-code ja \
--query 'TranslatedText' --output text
```

## Step 4: Auto-detect source language

Use `auto` as the source language code to let Translate detect the language:

```bash
aws translate translate-text \
--text "Amazon Translate ist ein neuronaler maschineller Übersetzungsdienst." \
--source-language-code auto --target-language-code en \
--query '{Translation:TranslatedText,DetectedLanguage:SourceLanguageCode}' --output table
```

## Step 5: List supported languages

```bash
aws translate list-languages \
--query 'Languages[:10].{Name:LanguageName,Code:LanguageCode}' --output table
```

## Cleanup

No cleanup needed. Translate is a stateless API — no resources are created.

The script automates all steps:

```bash
bash amazon-translate-gs.sh
```
60 changes: 60 additions & 0 deletions tuts/091-amazon-translate-gs/amazon-translate-gs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash
# Tutorial: Translate text between languages with Amazon Translate
# Source: https://docs.aws.amazon.com/translate/latest/dg/get-started.html

WORK_DIR=$(mktemp -d)
LOG_FILE="$WORK_DIR/translate-$(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"

TEXT="Amazon Translate is a neural machine translation service that delivers fast, high-quality, affordable, and customizable language translation."

echo ""
echo "Source text (English):"
echo " $TEXT"
echo ""

# Step 1: Translate English to Spanish
echo "Step 1: English → Spanish"
aws translate translate-text --text "$TEXT" \
--source-language-code en --target-language-code es \
--query 'TranslatedText' --output text
echo ""

# Step 2: Translate English to French
echo "Step 2: English → French"
aws translate translate-text --text "$TEXT" \
--source-language-code en --target-language-code fr \
--query 'TranslatedText' --output text
echo ""

# Step 3: Translate English to Japanese
echo "Step 3: English → Japanese"
aws translate translate-text --text "$TEXT" \
--source-language-code en --target-language-code ja \
--query 'TranslatedText' --output text
echo ""

# Step 4: Auto-detect source language
echo "Step 4: Auto-detect source language (German input)"
GERMAN="Amazon Translate ist ein neuronaler maschineller Übersetzungsdienst."
echo " Input: $GERMAN"
aws translate translate-text --text "$GERMAN" \
--source-language-code auto --target-language-code en \
--query '{Translation:TranslatedText,DetectedLanguage:SourceLanguageCode}' --output table
echo ""

# Step 5: List supported languages
echo "Step 5: Listing supported languages (first 10)"
aws translate list-languages --query 'Languages[:10].{Name:LanguageName,Code:LanguageCode}' --output table

echo ""
echo "Tutorial complete. No resources were created — Translate is a stateless API."
rm -rf "$WORK_DIR"
Loading
Loading