---
title: "How to Trigger AWS Lambda After Uploading 7 Files to S3: A Smart Event-Driven Architecture"
description: "Trigger AWS Lambda only after 7 S3 files are uploaded using SQS. Build a scalable, serverless batch processing flow with S3, SQS, and Lambda"
url: https://srinimf.com/2025/06/29/how-to-trigger-aws-lambda-after-uploading-7-files-to-s3-a-smart-event-driven-architecture/
date: 2025-06-29
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2025/06/trigger-lambda-function-aws.png?fit=2240%2C1260&ssl=1
categories: ["AWS"]
tags: ["AWS Lambda batch file processing", "AWS S3 trigger Lambda after multiple files", "S3 SQS Lambda architecture", "Trigger Lambda after N files upload"]
type: post
lang: en
---

# How to Trigger AWS Lambda After Uploading 7 Files to S3: A Smart Event-Driven Architecture

## Introduction

Amazon S3 is one of the most popular object storage services used to store anything from data backups to application assets. [AWS Lambda](https://srinimf.com/2024/10/15/aws-lambda-vs-step-functions-key-differences-explained/) is a serverless compute service that lets you run code in response to events. A common use case involves triggering a Lambda function after files are uploaded to an S3 bucket.

Related[Step-by-Step Guide for AWS Kafka and Kinesis Integration](https://srinimf.com/2025/01/06/step-by-step-guide-for-aws-kafka-and-kinesis-integration/)

But what if you want to trigger Lambda **only after 7 files** have been uploaded?

This article walks you through [how to](https://srinimf.com/2022/08/20/how-to-resolve-aws-cloud-tickets-and-save-sla-time/) set up such a scenario using S3, Amazon SQS, and Lambda together. We’ll explain why direct S3-to-Lambda won’t help you here, and how [to build](https://srinimf.com/2021/09/11/how-to-get-grip-on-micro-services-for-better-salary/) an event-driven, cost-effective, and scalable solution instead.

Related[AWS: 3 Easy to Write Lambda Functions](https://srinimf.com/2024/09/08/aws-3-easy-to-write-lambda-functions/)

## Why S3 Event Notifications Alone Won’t Work

By default, Amazon S3 event notifications trigger Lambda for **each object uploaded** to a bucket. That means if you upload 7 files, Lambda gets triggered **7 times**—once for each file.

Related[Why You Didn’t Get Promotion: Watch the Video](https://srinimf.com/2019/03/24/not-promoted-a-useful-video-to-watch-now-why/)

This is not efficient if:

- You want to process files in batches.
- You want to reduce the number of Lambda invocations (to save costs).
- Your logic depends on all 7 files being present before processing starts.

So, how do we fix this?

## Solution Overview: S3 + SQS + Lambda

Here’s the architecture to trigger Lambda **only after 7 files are uploaded**:

1. Configure **Amazon S3** to send event notifications to an **[Amazon SQS queue](https://srinimf.com/tag/s3-sqs-lambda-architecture/)**.
2. Set up a **Lambda function** to poll the queue.
3. The Lambda function processes messages **only when 7 files** are received.

This design is scalable, decoupled, and follows serverless best practices.

## Step-by-Step Implementation

### Step 1: Create an Amazon SQS Queue

1. Go to the Amazon SQS console.
2. Create a new standard queue (not FIFO).
3. Name it something like `s3-upload-queue`.
4. Enable access permissions for S3 to send messages to it.

### Step 2: Set Up S3 Event Notifications

1. Go to your [Amazon S3 bucket.](https://srinimf.com/tag/aws-s3-access-permissions/)
2. In the “Properties” tab, scroll to **Event notifications**.
3. Create a new event.
   - **Event type**: `PUT` (for new file uploads).
   - **Destination**: Your SQS queue.
4. Save the changes.

Now, every time a file is uploaded to your bucket, a message will be sent to the SQS queue.

### Step 3: Create and Configure a Lambda Function

1. Go to the AWS Lambda console.
2. Create a new function named `ProcessBatchOf7Files`.
3. Set the trigger source as your SQS queue.
4. In the function code:
   - Collect messages.
   - Check if there are **7 file upload events**.
   - Only then, proceed with processing.
5. Optionally, store or checkpoint the state using Amazon DynamoDB to handle retries or partial batches.

Here’s some sample pseudocode for the Lambda function:

```
def lambda_handler(event, context):
    messages = event['Records']
    
    if len(messages) >= 7:
        file_keys = [msg['body'] for msg in messages[:7]]
        # Process files
        print("Processing these 7 files:", file_keys)
        # Delete processed messages (handled automatically if no error)
    else:
        print("Less than 7 files received. Waiting for more.")
```

Related[How to Create a Generic Stored Procedure for KPI Calculation (SQL + AWS Lambda)](https://srinimf.com/2026/04/04/how-to-create-a-generic-stored-procedure-for-kpi-calculation-sql-aws-lambda/)

## Additional Enhancements

- Use Amazon EventBridge if your architecture involves multiple event sources or complex rules.
- Store a count of uploaded files temporarily in DynamoDB to manage batches more flexibly.
- Set up DLQs (dead-letter queues) for Lambda and SQS to handle failed messages.

Related[AWS Simple Queue Service: Here is Default Retention Period](https://srinimf.com/2021/07/24/aws-simple-queue-service-here-is-default-retention-period/)

## Benefits of This Approach

- ✅ **Batch Processing**: Trigger Lambda only when a batch of 7 files is ready.
- ✅ **Cost-Effective**: Fewer invocations, reduced Lambda duration.
- ✅ **Scalable**: Can easily modify the batch size or integrate with other services.
- ✅ **Decoupled**: SQS acts as a buffer and decouples the upload from the processing.

## Conclusion

If your use case demands triggering a Lambda function **only after 7 files** are uploaded to an S3 bucket, relying solely on S3 event notifications won’t cut it. By integrating **Amazon S3**, **SQS**, and **Lambda**, you gain precise control over when and how your function is triggered. This serverless, event-driven architecture is ideal for batch processing, and it scales effortlessly with your workload.

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2025%2F06%2F29%2Fhow-to-trigger-aws-lambda-after-uploading-7-files-to-s3-a-smart-event-driven-architecture%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2025%2F06%2Ftrigger-lambda-function-aws.png%3Ffit%3D1200%252C675%26ssl%3D1&description=How%20to%20Trigger%20AWS%20Lambda%20After%20Uploading%207%20Files%20to%20S3%3A%20A%20Smart%20Event-Driven%20Architecture)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2025/06/29/how-to-trigger-aws-lambda-after-uploading-7-files-to-s3-a-smart-event-driven-architecture/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2025/06/29/how-to-trigger-aws-lambda-after-uploading-7-files-to-s3-a-smart-event-driven-architecture/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2025/06/29/how-to-trigger-aws-lambda-after-uploading-7-files-to-s3-a-smart-event-driven-architecture/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2025/06/29/how-to-trigger-aws-lambda-after-uploading-7-files-to-s3-a-smart-event-driven-architecture/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20How%20to%20Trigger%20AWS%20Lambda%20After%20Uploading%207%20Files%20to%20S3%3A%20A%20Smart%20Event-Driven%20Architecture&body=https%3A%2F%2Fsrinimf.com%2F2025%2F06%2F29%2Fhow-to-trigger-aws-lambda-after-uploading-7-files-to-s3-a-smart-event-driven-architecture%2F&share=email)
-

### Like this:

Like Loading…
