---
title: "Production Observability for a Lambda Service"
description: "Baseline production observability for a Lambda service on AWS - log retention, SNS alerting, error and latency alarms, a CloudWatch dashboard, and X-Ray tracing."
url: "https://www.pulumi.com/dev/examples/aws-ts-production-observability/"
image: "https://www.pulumi.com/assets/og/dev/examples/aws-ts-production-observability.png"
---

# Production Observability for a Lambda Service

Baseline production observability for a Lambda service on AWS - log retention, SNS alerting, error and latency alarms, a CloudWatch dashboard, and X-Ray tracing.

- Source on GitHub: https://github.com/pulumi/examples/tree/master/aws-ts-production-observability
- Deploy with Pulumi: https://app.pulumi.com/new?template=https%3A%2F%2Fgithub.com%2Fpulumi%2Fexamples%2Ftree%2Fmaster%2Faws-ts-production-observability

## Get started with this example

This example lives in the [pulumi/examples](https://github.com/pulumi/examples/tree/master/aws-ts-production-observability) repo. Pull down just this directory to follow along:

```bash
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examples
git -C pulumi-examples sparse-checkout set aws-ts-production-observability
cd pulumi-examples/aws-ts-production-observability
```

Wiring up monitoring after the fact is tedious and easy to get wrong. This example provisions a baseline observability stack for an AWS Lambda service so a new service is watched from its first deploy.

It creates:

- A CloudWatch **log group** with a 30-day retention policy.
- An **SNS topic** with an email subscription for alarm notifications.
- CloudWatch **metric alarms** for function errors and high latency.
- A **CloudWatch dashboard** charting the function's error count and duration.
- A small **sample Lambda function** with AWS X-Ray active tracing enabled, standing in for the workload you want to observe.

Swap the sample function for your real workload (or point the alarms and dashboard at an existing function name) to reuse this as the monitoring layer for any Lambda service.

## Prerequisites

1. [Install Pulumi](https://www.pulumi.com/docs/get-started/install/)
1. [Configure your AWS credentials](https://www.pulumi.com/docs/intro/cloud-providers/aws/setup/)
1. [Install Node.js](https://www.pulumi.com/docs/intro/languages/javascript/)

## Deploying and running the program

1.  Create a new stack:

    ```bash
    pulumi stack init dev
    ```

1.  Set the AWS region and the email address to notify:

    ```bash
    pulumi config set aws:region us-west-2
    pulumi config set notificationEmail you@example.com
    ```

1.  Install dependencies:

    ```bash
    npm install
    ```

1.  Run `pulumi up` to preview and deploy:

    ```bash
    pulumi up
    ```

1.  AWS sends a confirmation email to the address you configured. Click the link in that email to activate the SNS subscription, otherwise alarm notifications won't be delivered.

1.  Inspect the stack outputs:

    ```bash
    pulumi stack output
    ```

    ```
    Current stack outputs (3):
        OUTPUT              VALUE
        dashboardId         dev-production-observability-dashboard
        notificationTarget  arn:aws:sns:us-west-2:***:dev-production-observability-alerts
        traceHook           Lambda dev-production-observability-sample has X-Ray tracing active
    ```

    Open the dashboard in the [CloudWatch console](https://console.aws.amazon.com/cloudwatch/home#dashboards:) to see the widgets.

## Clean up

To tear down the resources, run:

```bash
pulumi destroy
pulumi stack rm
```

## Summary

In this example you deployed a reusable observability baseline for an AWS Lambda service: centralized logs, email alerting through SNS, error and latency alarms, a dashboard, and X-Ray tracing. Point it at your own function to get production monitoring in place from day one.
