An event-driven AWS serverless solution that automatically backs up files uploaded to an S3 bucket and sends real-time notifications via SNS.
When a new object is uploaded to the source S3 bucket, a Lambda function is triggered that:
- Copies the object into a dedicated backup S3 bucket, preserving the original key.
- Publishes a JSON notification to an SNS topic (if configured) containing the source bucket, object key, backup bucket, and a UTC timestamp.
- Skips objects that already exist in the backup bucket (idempotent).
Source S3 Bucket
│
│ s3:ObjectCreated:*
▼
Lambda Function (dotnet8)
├──► Copy object ──► Backup S3 Bucket
└──► Publish notification ──► SNS Topic
| Resource | Type | Description |
|---|---|---|
Bucket |
AWS::S3::Bucket |
Source bucket — triggers the Lambda on new uploads |
BackupBucket |
AWS::S3::Bucket |
Destination bucket — receives backup copies |
NotificationTopic |
AWS::SNS::Topic |
SNS topic for backup notifications |
S3Function |
AWS::Serverless::Function |
Lambda function (.NET 8) that performs the backup |
Both S3 buckets use DeletionPolicy: Retain to prevent accidental data loss on stack deletion.
FileBackupSystem/
└── src/
└── Modules/
└── FileBackupSystemModule/
├── Function.cs # Lambda handler
├── FileBackupSystemModule.csproj # .NET 8 project file
├── serverless.template # AWS SAM / CloudFormation template
└── aws-lambda-tools-defaults.json # Lambda Tools CLI defaults
The Lambda function reads the following environment variables at startup:
| Variable | Required | Description |
|---|---|---|
BACKUP_BUCKET |
Yes | Name of the S3 bucket to copy objects into |
SNS_TOPIC_ARN |
No | ARN of the SNS topic to publish notifications to |
The SAM template wires these up automatically from the provisioned resources.
- .NET 8 SDK
- AWS CLI configured with appropriate credentials
- AWS SAM CLI
- Amazon.Lambda.Tools global tool (see below)
# Install (if not already installed)
dotnet tool install -g Amazon.Lambda.Tools
# Or update to the latest version
dotnet tool update -g Amazon.Lambda.Toolsdotnet lambda deploy-serverless is the recommended approach for .NET Lambda functions. It runs dotnet publish internally, ensuring all required runtime artifacts (including .deps.json) are correctly packaged before deployment.
cd src/Modules/FileBackupSystemModule
dotnet lambda deploy-serverless --stack-name file-backup-system --resolve-s3 true Right-click the FileBackupSystemModule project in Solution Explorer and select Publish to AWS Lambda.
Warning
sam build does not run dotnet publish for .NET Lambda functions. Deploying with sam build alone will produce an incomplete package that is missing the required .deps.json file, causing a Runtime.ExitError at cold start. Run dotnet publish first to work around this.
cd src/Modules/FileBackupSystemModule
# Publish the .NET project first so sam build picks up the correct artifacts
dotnet publish -c Release
sam build --template-file serverless.template
sam deploy --guided --template-file serverless.template| Parameter | Default | Description |
|---|---|---|
BackupBucketName |
(auto-generated) | Name of the backup S3 bucket. Leave blank to let CloudFormation generate a name. |
Default values for Lambda Tools CLI and Visual Studio are stored in:
aws-lambda-tools-defaults.json— region, build configuration, and template path.
After deployment, the CloudFormation stack exposes the following outputs:
| Output | Description |
|---|---|
Bucket |
Name of the source S3 bucket |
BackupBucket |
Name of the backup S3 bucket |
S3FunctionArn |
ARN of the Lambda function |
NotificationTopicArn |
ARN of the SNS notification topic |
Warning
Both S3 buckets (Bucket and BackupBucket) have DeletionPolicy: Retain in the template. They will not be deleted when the stack is removed — you must empty and delete them manually afterwards if no longer needed.
cd src/Modules/FileBackupSystemModule
dotnet lambda delete-serverless --stack-name file-backup-system --region eu-west-1cd src/Modules/FileBackupSystemModule
sam delete --stack-name file-backup-system --region eu-west-1After the stack is deleted, remove the buckets via the AWS CLI:
# Repeat for both the source bucket and the backup bucket
aws s3 rm s3://<bucket-name> --recursive
aws s3api delete-bucket --bucket <bucket-name> --region eu-west-1- Runtime: .NET 8 (AWS Lambda)
- IaC: AWS SAM (CloudFormation)
- Trigger: Amazon S3 event notifications
- Storage: Amazon S3
- Notifications: Amazon SNS
- Region:
eu-west-1(configurable)