Skip to content

An IaC that creates an S3 bucket, with a Lambda function that is triggered when an object is added to the bucket. It then sends an email notification to the subscribed email detailing the uploaded object

License

Notifications You must be signed in to change notification settings

Lakunzo/terraform-S3-notifications

Repository files navigation

Create an S3 Bucket with KMS Key, Lambda, and SNS Notifications

Project Overview

This project is an alert notification system that send an email to the bucket owner when an object is uploaded to an S3 bucket. It leverages Amazon S3, IAM, Lambda with Python, and SNS topics. The details of the notification include - the bucket name, file name, file size, upload date and time (UTC) and AWS account used to upload the object.

Archtiectural Diagram

Technologies Used

  • Cloud Provider - AWS
  • Services Used - S3 bucket, IAM, Lambda, SNS
  • Programming Language - Python 3.11

Setup Guide

Clone the Repository

git clone https://github.com/Lakunzo/terraform-S3-notifications.git

Modify the variables.tf and iamrole.tf

Variables.tf

Make changes to the following variables

  • aws-access-key - aws access key for programmatic functions
  • aws-secret-key - aws secret key for programmatic functions
  • aws-token-key (Optional) - aws token key for programmatic functions
  • sns-endpoint - email to subecribe and receive notifications

Keymanagement.tf

  • AWS Principal - to allow access to the account and user ID with permissions to create and administer KMS keys

Run the following Terraform commands

  1. Initialize Terraform backend
terraform init
  1. Validate the Terraform configuration
terraform validate
  1. Run the Terraform plan to view the resources that will be created
terraform plan
  1. Run Terraform apply to create the needed resources and type 'yes' to proceed
terraform apply
  1. Confirm if you have the following resources created
    • An S3 bucket with SSE-KMS keys, and an event notification.
    • An SSE-KMS Key attached to the S3 bucket
    • A Lambda function with a Python code
    • An SNS topics with a subscription sent to the configured email address
    • An IAM role with required permission policies

Confirm SNS Subscription

Click the link in the email to confirm the SNS subscription. Subscription Email

Upload an object to test notification

Upload an object to the S3 bucket to test the email notification Notification Email

  1. Run Terraform destroy to remove all created resources. Type 'yes' to proceed
terraform destroy

About

An IaC that creates an S3 bucket, with a Lambda function that is triggered when an object is added to the bucket. It then sends an email notification to the subscribed email detailing the uploaded object

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published