Technologies:
☁️ AWS: 🪣 S3 bucket, ⚡️ lambda function, 🔔 SNS, 📬 SQS
🤖 IaC: 🏗️ Terraform
🔄 CD: 🛠️ GitLab
Project resume: Email notification system developed in AWS. Once a file is uploaded to an s3 bucket it triggers an event which calls a lambda function and notifies service subscribers that a file has been uploaded.
📌Requirements
🎯Workflow
1️⃣ Source code 📄
2️⃣ Lambda function ⚡️
3️⃣ Deploy to AWS through GitLab 🚀
1️⃣ Source code 📄
Structure
terraform
└── terraform
├── bucket
│ ├── main.tf
│ └── output.tf
│ └── variables.tf
├── lambda
│ ├── main.tf
│ └── output.tf
│ └── variables.tf
│ └── lambda_assume_role_policy.json
│ └── lambda_policy.json
│ └── lambda_function.py
│ └── lambda_function.zip
├── sns
│ ├── main.tf
│ └── output.tf
│ └── variables.tf
├── sqs
│ ├── main.tf
│ └── output.tf
│ └── variables.tf
├── main.tf
└── providers.tf
It is organized into modules dedicated to different AWS services, each designed to serve a specific purpose and facilitate the management and scalability of the cloud environment.In addition, using Terraform to orchestrate these modules ensures a consistent and controlled deployment of the infrastructure, aligned with best practices for configuration management and agile development in the cloud.
2️⃣ Lambda function ⚡️
import json
import boto3
# Initialize AWS clients
s3_client = boto3.client('s3')
sns_client = boto3.client('sns')
sqs_client = boto3.client('sqs')
def lambda_handler(event, context):
# Define SNS topic ARN and SQS queue URL
sns_topic_arn = 'arn:aws:sns:us-east-2:087243254862:notifcationsystem-bucket'
sqs_queue_url = 'https://sqs.us-east-2.amazonaws.com/087243254862/notification'
# Process S3 event records
for record in event['Records']:
# Print the entire event for debugging purposes
print(event)
# Extract S3 bucket and object information from the event record
s3_bucket = record['s3']['bucket']['name']
s3_key = record['s3']['object']['key']
# Example: Prepare metadata to send to SQS
metadata = {
'bucket': s3_bucket,
'key': s3_key,
'timestamp': record['eventTime']
}
# Send metadata to SQS queue
sqs_response = sqs_client.send_message(
QueueUrl=sqs_queue_url,
MessageBody=json.dumps(metadata)
)
# Example: Prepare notification message to send to SNS
notification_message = f"New file uploaded to S3 bucket '{s3_bucket}' with key '{s3_key}'"
# Publish notification message to SNS topic
sns_response = sns_client.publish(
TopicArn=sns_topic_arn,
Message=notification_message,
Subject="File Upload Notification"
)
# Return a success response
return {
'statusCode': 200,
'body': json.dumps('Processing complete')
}
3️⃣ GitLab workflow 🚀
- Add pipeline
🔑Add access key from AWS into secrets in GitLab(Create a User for this purpose)
▶️ Run


Top comments (0)