Skip to content
Branch: master
Find file History
Latest commit 36607b6 Oct 21, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
images readme Apr 11, 2019
processor error processor sample Apr 11, 2019
random-error error processor sample Apr 11, 2019
.gitignore cleanup Aug 30, 2019 cleanup Aug 30, 2019 cleanup Aug 30, 2019 cleanup Aug 30, 2019 fix file name Oct 22, 2019
error-processor.yaml note dependency in template Jun 24, 2019 error processor sample Apr 11, 2019 error processor sample Apr 23, 2019

Error Processing with CloudWatch Logs and X-Ray

This sample application triggers a Lambda function when CloudWatch Logs detects the word ERROR in a log stream. The function downloads the full log stream and the X-Ray trace for the request that caused the error. It stores both in an Amazon S3 bucket.

This project contains the following resources:

  • processor - A Node.js function that retrieves logs and traces, and stores them in Amazon S3.
  • random-error - A Node.js function that generates errors at random.
  • error-processor.yaml - An AWS CloudFormation template that creates an application with the processor and random-error functions.
  •,, etc. - Shell scripts that use the AWS CLI to deploy and manage the application.


Use the following instructions to deploy the sample application. For more information on the application's architecture and implementation, see Error Processor Sample Application for AWS Lambda in the developer guide.



Download or clone this repository.

$ git clone
$ cd aws-lambda-developer-guide/sample-apps/error-processor

Run to create a new bucket for deployment artifacts. Or, if you already have a bucket, replace MY_BUCKET in with the name of an existing bucket.

error-processor$ ./
make_bucket: lambda-artifacts-a5e491dbb5b22e0d

Run to install the dependencies for each function, including the X-Ray SDK.

error-processor$ ./
added 16 packages from 18 contributors and audited 18 packages in 0.926s
found 0 vulnerabilities

added 17 packages from 19 contributors and audited 19 packages in 0.916s
found 0 vulnerabilities


Run to deploy the application.

error-processor$ ./
Uploading to e678bc216e6a0d510d661ca9ae2fd941  2737254 / 2737254.0  (100.00%)
Successfully packaged artifacts and wrote output template to file out.yml.
Waiting for changeset to be created..
Waiting for stack create/update to complete
Successfully created/updated stack - error-processor

This script uses AWS CloudFormation to deploy the Lambda functions, an IAM role, and a CloudWatch Logs subscription that triggers the processor function. If the AWS CloudFormation stack that contains the resources already exists, the script updates it with any changes to the template or function code.


To generate logs and errors, invoke the random error function.

error-processor$ ./
    "StatusCode": 200,
    "ExecutedVersion": "$LATEST"
    "StatusCode": 200,
    "FunctionError": "Handled",
    "ExecutedVersion": "$LATEST"
    "StatusCode": 200,
    "ExecutedVersion": "$LATEST"

The functions in this application are instrumented with AWS X-Ray. Open the X-Ray console to view the service map. The following service map shows the random error function generating errors for some requests. It also shows the processor function calling X-Ray, CloudWatch Logs, and Amazon S3.

Service Map

Choose a node in the main function graph. Then choose View traces to see a list of traces. Choose any trace to view a timeline that breaks down the work done by the function.


Finally, view the logs and traces that the function stores in Amazon S3.

To view the output

  1. Open the applications page in the Lambda console.
  2. Choose error-processor.


  1. Choose bucket.
  2. Choose errors.
  3. Choose a request ID.
  4. For each file, check the box next to the filename and then choose Download.


To delete the application, run the cleanup script.

error-processor$ ./
You can’t perform that action at this time.