|
| 1 | +# Translate Text in real-time using AWS Lambda and Amazon Translate |
| 2 | + |
| 3 | +This pattern contains source code and supporting files for a serverless application deployable with Terraform. The pattern demonstrates how to create an AWS Lambda function that integrates with Amazon Translate to perform real-time text translation between languages. |
| 4 | + |
| 5 | +Learn more about this pattern at Serverless Land Patterns: https://serverlessland.com/patterns/lambda-translate-tf |
| 6 | + |
| 7 | +Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the [AWS Pricing page](https://aws.amazon.com/pricing/) for details. You are responsible for any AWS costs incurred. No warranty is implied in this example. |
| 8 | + |
| 9 | +## Requirements |
| 10 | + |
| 11 | +* [Create an AWS account](https://portal.aws.amazon.com/gp/aws/developer/registration/index.html) if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources. |
| 12 | +* [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured |
| 13 | +* [Git Installed](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) |
| 14 | +* [Terraform](https://learn.hashicorp.com/tutorials/terraform/install-cli?in=terraform/aws-get-started) installed |
| 15 | + |
| 16 | +## Deployment Instructions |
| 17 | + |
| 18 | +1. Create a new directory, navigate to that directory in a terminal and clone the repository: |
| 19 | + ``` |
| 20 | + git clone https://github.com/aws-samples/serverless-patterns |
| 21 | + ``` |
| 22 | +2. Change directory to the pattern directory: |
| 23 | + ``` |
| 24 | + cd serverless-patterns/lambda-translate-tf |
| 25 | + ``` |
| 26 | +3. From the command line, initialize Terraform to downloads and install the providers defined in the configuration: |
| 27 | + ``` |
| 28 | + terraform init |
| 29 | + ``` |
| 30 | +4. From the command line, apply the configuration in the main.tf file: |
| 31 | + ``` |
| 32 | + terraform apply |
| 33 | + ``` |
| 34 | +5. Note the outputs from the deployment process. These contain the resource names and/or ARNs which are used for testing. |
| 35 | +
|
| 36 | +## How it works |
| 37 | +
|
| 38 | +The pattern uses an AWS Lambda function that integrates with Amazon Translate to perform real-time text translation. When invoked via the AWS CLI, the Lambda function takes three parameters (source text, source language, and target language) and uses Amazon Translate to convert the text from one language to another (for example English to German). |
| 39 | +
|
| 40 | +"The example demonstrates translation from English to German language. For a complete list of supported languages, please refer to the [Amazon Translate documentation](https://docs.aws.amazon.com/translate/latest/dg/what-is-languages.html)." |
| 41 | +
|
| 42 | +
|
| 43 | +## Testing |
| 44 | +
|
| 45 | +Replace "{LambdaFunctionName}" with the function name as seen in the output of terraform template |
| 46 | +
|
| 47 | +``` |
| 48 | +aws lambda invoke --function-name {LambdaFunctionName} --invocation-type RequestResponse --cli-binary-format raw-in-base64-out --payload "{\"text\":\"I am very happy\", \"sl\":\"en\",\"tl\":\"de\"}" response.json |
| 49 | +``` |
| 50 | +
|
| 51 | +After running the command, open the generated response.json file to see the translated output: |
| 52 | +``` |
| 53 | +Ich freue mich sehr |
| 54 | +``` |
| 55 | +
|
| 56 | +## Cleanup |
| 57 | +
|
| 58 | +1. Delete all created resources by Terraform |
| 59 | + ```bash |
| 60 | + terraform destroy |
| 61 | + ``` |
| 62 | +2. Confirm all created resources has been deleted |
| 63 | + ```bash |
| 64 | + terraform show |
| 65 | + ``` |
| 66 | +---- |
| 67 | +Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 68 | +
|
| 69 | +SPDX-License-Identifier: MIT-0 |
0 commit comments