Unlocking language boundaries: Translate software logs with Amazon Translate for seamless help

Software logs are a necessary piece of knowledge that gives essential insights into the interior workings of an software. This consists of priceless data akin to occasions, errors, and person interactions that may support an software developer or an operations help engineer to debug and supply help. Nevertheless, when these logs are offered in languages aside from English, it creates a big hurdle for builders who can’t learn the content material, and hinders the help crew’s capacity to determine and handle points promptly.

On this put up, we discover an answer on how one can unlock language boundaries utilizing Amazon Translate, a completely managed neural machine translation service for translating textual content to and from English throughout a wide range of supported languages. The answer will complement your current logging workflows by mechanically translating all of your functions logs in Amazon CloudWatch in actual time, which might alleviate the challenges posed by non-English software logs.

Answer overview

This resolution reveals you the way you need to use three key providers to automate the interpretation of your software logs in an event-driven method:

  • CloudWatch Logs is used to watch, retailer, and entry your log recordsdata generated from numerous sources akin to AWS providers and your functions
  • Amazon Translate is used to carry out the interpretation of textual content to and from English
  • AWS Lambda is a compute service that permits you to run codes to retrieve software logs and translate them by using the Amazon Translate SDK

The next diagram illustrates the answer structure.

The workflow consists of the next steps:

  1. A customized or third-party software is hosted on an Amazon Elastic Compute Cloud (Amazon EC2) occasion and the generated software logs are uploaded to CloudWatch Logs by way of the CloudWatch Logs agent.
  2. Every log entry written to CloudWatch Logs triggers the Lambda operate subscribed to the CloudWatch log group.
  3. The operate processes the contents of the log entry and makes use of Amazon Translate SDK translate_text to translate the log content material.
  4. The translated log content material is returned to the operate.
  5. The operate writes the translated log content material again to CloudWatch Logs in a unique log group.

The complete course of occurs mechanically in actual time, and your builders will have the ability to entry the translated software logs from the CloudWatch log teams with no change in how your current software writes logs to CloudWatch.


To comply with by the directions on this resolution, you want an AWS account with an AWS Identity and Access Management (IAM) person who has permission to AWS CloudFormation, Amazon Translate, CloudWatch, Lambda, and IAM.

Deploy the answer

To get began, launch the next CloudFormation template to create a Lambda operate, two CloudWatch log teams, and IAM function. Proceed to deploy with the default settings. This template takes about 1 minute to finish.

After the stack is created efficiently, you’ll be able to assessment the Lambda operate by navigating to the Lambda console and finding the operate translate-application-logs.

You’ll be able to observe that there’s a CloudWatch Logs set off added to the operate.

You’ll be able to view the small print of the set off configuration by navigating to the Configuration tab and selecting Triggers within the navigation pane.

You’ll be able to affirm that the set off has been configured to subscribe to log occasions from the log group /applicationlogs. That is the place your non-English software logs shall be written to.

Subsequent, select Surroundings variables within the navigation pane.

Two surroundings variables are offered right here:

  • source_language – The unique language that the appliance log is in (for instance, ja for Japanese)
  • target_language – The goal language to translate the appliance log to (for instance, en for English)

For an inventory of supported languages, discuss with Supported languages and language codes.

Subsequent, go to the Code tab and assessment the operate logic:

import json, boto3, gzip, base64, os

translate = boto3.shopper(service_name="translate", region_name=os.environ['AWS_REGION'], use_ssl=True)
logs = boto3.shopper('logs')
def lambda_handler(occasion, context):
    # retrieve log messages
    encoded_zipped_data = occasion['awslogs']['data']
    zipped_data = base64.b64decode(encoded_zipped_data)
    information = gzip.decompress(zipped_data)
    json_log = json.hundreds(information)
    logGroup = json_log['logGroup']+'-'+os.environ['target_language']
    logStream = json_log['logStream']
    # verify  if log group exists, create if not    
    dlg = logs.describe_log_groups(logGroupNamePrefix=logGroup)
    if len(dlg['logGroups']) == 0:

    # verify if log stream exists, create if not    
    dls = logs.describe_log_streams(logGroupName=logGroup, logStreamNamePrefix=logStream)
    if len(dls['logStreams']) == 0:
        logs.create_log_stream(logGroupName=logGroup, logStreamName=logStream)

    # translate log occasion messages from supply language to focus on language
    for logevent in json_log['logEvents']:
        logevent['message'] = translate.translate_text(Textual content=logevent['message'], SourceLanguageCode=os.environ['source_language'], TargetLanguageCode=os.environ['target_language']).get('TranslatedText')
        del logevent['id']

    # write translated log occasions again to a unique log group in CloudWatch
        logGroupName = logGroup,
        logStreamName = logStream,
        logEvents = json_log['logEvents']
    # return success
    return {
        'statusCode': 200,
        'physique': 'Translation success!'

Take a look at the answer

Lastly, to check the answer, you’ll be able to create a log message by the CloudWatch console and select the created log group and log stream.

After creating your log messages, it is possible for you to to see it translated instantly.

Clear up

To scrub up the sources created on this put up, delete the CloudFormation stack by way of the CloudFormation console.


This put up addressed the problem confronted by builders and help groups when software logs are offered in languages aside from English, making it tough for them to debug and supply help. The proposed resolution makes use of Amazon Translate to mechanically translate non-English logs in CloudWatch, and supplies step-by-step steering on deploying the answer in your surroundings. By this implementation, builders can now seamlessly bridge the language barrier, empowering them to deal with points swiftly and successfully.

Check out this implementation and tell us your ideas within the feedback.

Concerning the writer

Xan Huang is a Senior Options Architect with AWS and relies in Singapore. He works with main monetary establishments to design and construct safe, scalable, and extremely accessible options within the cloud. Outdoors of labor, Xan spends most of his free time along with his household and documenting his daughter’s rising up journey.

Leave a Reply

Your email address will not be published. Required fields are marked *