---
title: How to Send AWS Lambda Logs API to S3
description: Practical example using Python of how to Send AWS Lambda Logs API to a S3 Bucket instead of Cloudwatch -Cost Saving Exercise-
image: https://www.dae.mn/hubfs/lambda_log_daemon.jpg
---

![](https://www.dae.mn/hubfs/lambda_log_daemon.jpg)

# How to Send AWS Lambda Logs API to S3

 Published by [ Gonzalo Fernandez ](https://www.dae.mn/blog/author/gonzalo-fernandez) on  20 November 2023

# Introduction

AWS Lambda is a powerful service that allows you to run code in response to events, such as user input or system events. In this blog post, we will show you how to log events in S3 using the AWS Lambda API.

AWS Cloudwatch is known as an expensive resource, one of its most expensive features is data ingestion (today it ranks at $0.50 per GB). 

In this article, we are going to DEMO how to skip CloudWatch Data Ingestion and use S3.

By default, AWS Lambda will stream the logs directory into Cloudwatch, but using the Concept of Lambda Extensions, we can skip that step and instead directly subscribe to the log streams within the Lambda Execution environment.

The Logs API allows extensions to subscribe to three different log streams:

- Function – Logs that the Lambda function generates and writes to stdout or stderr.
- Extension – Logs that the extension code generates.
- Platform – Logs that the runtime platform generates, which record events and errors related to invocations and extensions.

 

In this article, we are going to DEMO the Function logs.

 

# DEMO

I will be using Python in this DEMO and it will have 2 components within the lambda space:

- Lambda function
- Lambda layer attached to the function

The reason for using a lambda layer is to provide flexibility to the main lambda function.

The code I am using is Terraform base and it’s stored in GitHub [here](https://github.com/Daemon-Solutions/aws_lambda_log_api/)

The terraform code will create the following resources:

- Lambda function
- Lambda Layer
- Two S3 buckets
  
    - data-storage-test (Where the lambda outputs will be stored)
    - my-lambda-layer-bucket-testing (In this bucket the zipped lambda layer will be stored)

Below is the log Output After running the Lambda (the data will NOT be sent to CloudWatch)

![8e3dbf69-8cf9-4909-9930-463dcb544c2b](https://www.dae.mn/hs-fs/hubfs/Downloads/8e3dbf69-8cf9-4909-9930-463dcb544c2b.png?width=2302&height=700&name=8e3dbf69-8cf9-4909-9930-463dcb544c2b.png)

Below is the S3 bucket with the log files containing 2 Lambda executions:

![4af773f4-404e-42b1-bab8-c9d918c14953](https://www.dae.mn/hs-fs/hubfs/Downloads/4af773f4-404e-42b1-bab8-c9d918c14953.png?width=509&height=444&name=4af773f4-404e-42b1-bab8-c9d918c14953.png)

Content of one of the log files as per below:

[{'time': '2023-08-26T16:26:50.313Z', 'type': 'platform.logsSubscription', 'record': {'name': 'logs_api_http_extension.py', 'state': 'Subscribed', 'types': ['platform', 'function']}}, {'time': '2023-08-26T16:26:50.587Z', 'type': 'platform.extension', 'record': {'name': 'logs_api_http_extension.py', 'state': 'Ready', 'events': ['INVOKE', 'SHUTDOWN']}}, {'time': '2023-08-26T16:26:50.590Z', 'type': 'platform.start', 'record': {'requestId': '3831bbf8-2c89-43ed-a01c-0a766fea440b', 'version': '$LATEST'}}, {'time': '2023-08-26T16:26:50.603Z', 'type': 'function', 'record': 'Inside Lambda function handler\n'}, {'time': '2023-08-26T16:26:50.624Z', 'type': 'platform.end', 'record': {'requestId': '3831bbf8-2c89-43ed-a01c-0a766fea440b'}}, {'time': '2023-08-26T16:26:50.624Z', 'type': 'platform.report', 'record': {'requestId': '3831bbf8-2c89-43ed-a01c-0a766fea440b', 'metrics': {'durationMs': 15.448, 'billedDurationMs': 16, 'memorySizeMB': 128, 'maxMemoryUsedMB': 79, 'initDurationMs': 834.953}}}]

 

# Further Information

[Lambda execution environment - AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtime-environment.html)

[Lambda Extensions API - AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-extensions-api.html)

[Lambda Logs API - AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-logs-api.html)

[GitHub - aws-samples/aws-lambda-extensions: A collection of sample extensions to help you get started with AWS Lambda Extensions](https://github.com/aws-samples/aws-lambda-extensions)

Tags: [aws](https://www.dae.mn/blog/tag/aws), [lambda](https://www.dae.mn/blog/tag/lambda), [cloudwatch](https://www.dae.mn/blog/tag/cloudwatch), [api](https://www.dae.mn/blog/tag/api), [github](https://www.dae.mn/blog/tag/github)

[Back to Blog](https://www.dae.mn/blog)

- [Tweet](https://twitter.com/share)

## Related Articles

<https://www.dae.mn/blog/resilient-cost-effective-and-tough.-what-the-uk-can-learn-from-south-african-fintech-market>

## [‘Resilient, cost-effective and tough.’ What the UK can learn from South African fintech market](https://www.dae.mn/blog/resilient-cost-effective-and-tough.-what-the-uk-can-learn-from-south-african-fintech-market)

 At Daemon, we are proud of our close ties to South Africa, and our connections to a new, unique...

[Read More ](https://www.dae.mn/blog/resilient-cost-effective-and-tough.-what-the-uk-can-learn-from-south-african-fintech-market)

<https://www.dae.mn/blog/a-secure-landing-zone-for-your-cloud-workloads-aws-control-tower-and-the-problems-it-solves>

## [A Secure Landing Zone for your Cloud Workloads: AWS Control Tower and the problems it solves.](https://www.dae.mn/blog/a-secure-landing-zone-for-your-cloud-workloads-aws-control-tower-and-the-problems-it-solves)

[Read More ](https://www.dae.mn/blog/a-secure-landing-zone-for-your-cloud-workloads-aws-control-tower-and-the-problems-it-solves)

<https://www.dae.mn/blog/were-going-to-aws-summit-london-heres-where-you-can-find-us>

## [We're going to AWS Summit London - here's where you can find us](https://www.dae.mn/blog/were-going-to-aws-summit-london-heres-where-you-can-find-us)

 From cloud migration and software engineering to artificial intelligence and machine learning,...

[Read More ](https://www.dae.mn/blog/were-going-to-aws-summit-london-heres-where-you-can-find-us)

[Follow us on LinkedIn ](https://www.linkedin.com/company/daemon-solutions/) [Follow us on Facebook ](https://www.instagram.com/daemon_consultancy/)

©2026 Daemon Solutions Ltd. | Company Number: 03442937 | VAT Number: 768365777 Paddington Clubhouse | Studio C, 21 Conduit Place, Paddington, London W2 1HS | United Kingdom

[![Daemon logo](https://www.dae.mn/hs-fs/hubfs/logo-daemo.png?width=386&height=98&name=logo-daemo.png "Daemon logo")](https://www.dae.mn/)