Amazon Translate
Hands-On
Demo

In this Demo, we will:-
1. Set up S3 buckets for source and translated documents
2. Create IAM roles and policies for Amazon Translate
3. Configure Amazon Translate for real-time translation
4. Set up batch translation jobs
5. Create a Lambda function for automated translation triggers
6. Test both real-time and batch translation scenarios
7. Monitor translation jobs and review results
8. Clean up resources
Agenda

Visual Representation

Create Source bucket
translate-demo-source-183101

Create Output bucket
translate-demo-output-183101

Create folder
input-documents

processed
Create target folder

Bulk Document - 1.txt
Global Supply Chain Management
Our company specializes in international logistics and supply chain optimization.
We provide end-to-end solutions including inventory management,
transportation coordination, and customs clearance services across 50+ countries.

Financial Services Overview
We offer comprehensive financial solutions including corporate banking,
investment advisory, risk management, and regulatory compliance support.
Our team of certified professionals ensures your business meets all
international financial standards.
Bulk Document - 2.txt

Technology Innovation Hub
Join our innovation center where cutting-edge technology meets practical business solutions.
We specialize in artificial intelligence, machine learning, cloud computing,
and digital transformation strategies.
Bulk Document - 3.txt

Upload to input-documents folder

Upload Succeeded

Create Role

AWSLambdaBasicExecutionRole
AWSLambdaBasicExecutionRole

TranslateFullAccess
TranslateFullAccess

AmazonS3FullAccess
AmazonS3FullAccess

Name, review, and create
TranslateLambdaRole

Review

Review

Welcome to our global business platform.
We provide comprehensive solutions for international commerce,
including multi-language support, currency conversion,
and cross-border logistics management.
Real-time translation

Additional settings

Application integration

Real-time translation

Real-time translation

Batch translation

Create translation job
demo-batch-translation-job

Input data



Output data


Customization - optional

Create an IAM role
Demo

demo-batch-translation-job translation job is in progress

demo-batch-translation-job Completed

Batch Translation - Result

Output

Real Time Translation Using Lambda Trigger
AutoTranslateFunction

Change default execution role

import json
import boto3
import urllib.parse
from datetime import datetime
def lambda_handler(event, context):
# Initialize AWS clients
translate_client = boto3.client('translate')
s3_client = boto3.client('s3')
# Parse S3 event
for record in event['Records']:
bucket = record['s3']['bucket']['name']
key = urllib.parse.unquote_plus(record['s3']['object']['key'])
try:
# Read the uploaded file
response = s3_client.get_object(Bucket=bucket, Key=key)
file_content = response['Body'].read().decode('utf-8')
# Translate the content
translation_response = translate_client.translate_text(
Text=file_content,
SourceLanguageCode='auto',
TargetLanguageCode='es' # Spanish
)
translated_text = translation_response['TranslatedText']
source_language = translation_response['SourceLanguageCode']
# Create output filename
output_key = f"translated/{key.split('/')[-1]}_translated_to_spanish.txt"
# Save translated content to output bucket
output_bucket = 'translate-demo-output-183101' # Replace with your actual output bucket name
s3_client.put_object(
Bucket=output_bucket,
Key=output_key,
Body=translated_text,
ContentType='text/plain'
)
# Log successful translation
print(f"Successfully translated {key} from {source_language} to Spanish")
return {
'statusCode': 200,
'body': json.dumps({
'message': 'Translation completed successfully',
'source_file': key,
'output_file': output_key,
'source_language': source_language
})
}
except Exception as e:
print(f"Error processing {key}: {str(e)}")
return {
'statusCode': 500,
'body': json.dumps({
'error': str(e),
'source_file': key
})
}

Deploy

Add trigger

Add trigger







Upload 4.txt to input bucket

CloudWatch Log groups
Translate


Log events

Check the translated folder of S3 output bucket

Translated Output
Clean Up

Empty the Bucket 1

Empty the Bucket 1

Delete the Bucket 1

Delete the Bucket 1

Empty the Bucket 2

Empty the Bucket 2

Delete the Bucket 2

Delete the Bucket 2

Delete the IAM Roles
Translate


Delete the Lambda Function

confirm
confirm
🙏
Thanks
for
Watching
Amazon Translate - Hands-On Demo
By Deepak Dubey
Amazon Translate - Hands-On Demo
Amazon Translate - Hands-On Demo
- 40