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.
This example lives in the pulumi/examples repository. Check out just this directory to use it:
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examplesgit -C pulumi-examples sparse-checkout set aws-ts-production-observabilitycd pulumi-examples/aws-ts-production-observabilityWiring 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#
Deploying and running the program#
-
Create a new stack:
Terminal window pulumi stack init dev -
Set the AWS region and the email address to notify:
Terminal window pulumi config set aws:region us-west-2pulumi config set notificationEmail you@example.com -
Install dependencies:
Terminal window npm install -
Run
pulumi upto preview and deploy:Terminal window pulumi up -
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.
-
Inspect the stack outputs:
Terminal window pulumi stack outputCurrent stack outputs (3):OUTPUT VALUEdashboardId dev-production-observability-dashboardnotificationTarget arn:aws:sns:us-west-2:***:dev-production-observability-alertstraceHook Lambda dev-production-observability-sample has X-Ray tracing activeOpen the dashboard in the CloudWatch console to see the widgets.
Clean up#
To tear down the resources, run:
pulumi destroypulumi stack rmSummary#
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.