Logs with Lambda
Send AWS log data from multiple services to Grafana Cloud using Lambda Promtail, a Lambda function that forwards logs to your stack using the Loki push API. Since AWS invokes the function only when new log data is available, you don’t have an always-on agent.
In the Cloud Provider Observability UI, you can generate a CloudFormation template or Terraform snippets, API credentials, and your Loki write endpoint, all of which you need to configure logs with Lambda.
For self-managed setups (container image from Amazon Elastic Container Registry (Amazon ECR), Amazon Kinesis, SQS, advanced relabeling), refer to the Lambda Promtail client documentation.
Supported log sources
Cloud Provider Observability supports the following AWS log sources:
| Log source | Description |
|---|---|
| Amazon CloudWatch Logs | Log groups from any CloudWatch-instrumented service (Lambda, ECS, EC2, and so on) |
| AWS CloudTrail | API activity and management event logs |
| VPC Flow Logs | Network traffic logs for your VPCs |
| Application Load Balancer (ALB) access logs | HTTP request logs from ALB instances |
| CloudFront access logs | CDN access logs stored in S3 |
| Amazon Kinesis Data Streams | Real-time streaming log data |
Choose a configuration guide
| If your logs are… | Follow |
|---|---|
| In Amazon CloudWatch Logs (subscription filter to Lambda) | Configure Amazon CloudWatch Logs with Lambda |
| Application Load Balancer access logs in S3 (often with EventBridge) | Configure Application Load Balancer logs |
Other S3-based AWS logs (for example AWS CloudTrail, Amazon VPC Flow Logs, or Amazon CloudFront access logs) use the same general pattern as load balancer logs: objects land in S3, then S3 or EventBridge triggers lambda-promtail. Use the ALB guide for the Grafana Cloud workflow, then adapt bucket names and permissions using the Lambda Promtail client reference and example Terraform.
How it works
- You deploy lambda-promtail in your AWS account.
- When a log event occurs, the source service writes logs to CloudWatch or an S3 bucket, depending on the service.
- The Lambda Promtail function is triggered by that event - either a CloudWatch subscription filter or an S3 (or EventBridge) notification.
- The Lambda Promtail function batches lines and pushes them to Grafana Cloud using the Loki push API.
- Your logs are available in Cloud Provider Observability in Grafana Cloud.
After logs arrive in Grafana Cloud Provider, you can:
- Query them using LogQL.
- Set up alerts based on log content.
- Perform cross-account and cross-region querying without additional configuration.
Note
Forwarding from CloudWatch Logs does not remove CloudWatch charges; you still pay AWS for ingestion and storage there.
Deployment options
Logs with Lambda can be deployed with either of the following methods:
- Terraform, for repeatable infrastructure-as-code deployments with support for arrays of log groups, buckets, and network settings
- CloudFormation, for AWS-native infrastructure definitions
Labels
lambda-promtail attaches internal labels you can use in LogQL.
The following are the ones most Grafana Cloud users need.
A full list, relabeling (RELABEL_CONFIGS), and behavior for Amazon Kinesis and multi-tenant setups are documented in the Lambda Promtail client documentation.
| Label | When it appears | Meaning |
|---|---|---|
__aws_log_type | Most events | Source class (for example CloudWatch vs S3 LB). |
__aws_cloudwatch_log_group | CloudWatch path | CloudWatch log group name. |
__aws_cloudwatch_log_stream | CloudWatch path, if KEEP_STREAM=true | CloudWatch log stream name. |
__aws_cloudwatch_owner | CloudWatch path | AWS account ID of the log group owner. |
__aws_s3_log_lb | ALB / S3 LB-style access logs | Load balancer name. |
__aws_s3_log_lb_owner | ALB / S3 LB-style access logs | AWS account ID that owns the load balancer. |
Extra labels: You can add comma-separated pairs (for example env,prod,team,platform) using the EXTRA_LABELS environment variable or CloudFormation ExtraLabels.
These extra labels appear as __extra_<name>=<value> on log lines.
For sample queries after setup, refer to the Explore logs section in Configure CloudWatch logs with Lambda or Configure Application Load Balancer logs.
Limitations and considerations
Keep the following in mind when using Logs with Lambda:
- CloudWatch-based collection is still subject to CloudWatch ingestion and retention costs.
- Some AWS log formats, such as default VPC Flow Logs, do not include a source timestamp, so the observed timestamp can reflect processing time instead.
- If you preserve high-cardinality identifiers such as log streams, label cardinality can increase significantly.
- Some advanced deployment patterns may require modifying the provided Terraform or CloudFormation templates.
Was this page helpful?
Related resources from Grafana Labs


