Skip to content

CodeGlynd/aws-lab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 

Repository files navigation

AWS Lab

Task 1

attatch IAM role to an ec2 instance which enables it to interact with an s3 bucket, create a new bucket and list buckets from cli

2024-08-23.06-51-05.mp4

Task 2

Create an S3 bucket that will trigger the Lambda function.
Create a Lambda function that sends an email notification when an object is uploaded to the S3 bucket.
Set up an S3 event notification to trigger the Lambda function when a new object is uploaded.
Test the setup by uploading an object to the S3 bucket and verifying that an email notification is received.

aws-task-2.mp4

Excludes

policies added to IAM Role attached to lambda not included in video

  • cloud watch log
  • EC2
  • Pinpoint Email
  • Route 53
  • S3
  • SES
  • SES Mail Manager
  • SES v2

lambda function deployment

import boto3
import json

def lambda_handler(event, context):
    
    for e in event["Records"]:
        bucketName = e["s3"]["bucket"]["name"]
        objectName = e["s3"]["object"]["key"]
        eventName = e["eventName"]
    
    bClient = boto3.client("ses")
    
    eSubject = 'AWS' + str(eventName) + 'Event'
    
    eBody = """
        <br>
        Hey,<br>
        
        Welcome to AWS S3 notification lambda trigger<br>
        
        We are here to notify you that {} an event was triggered.<br>
        Bucket name : {} <br>
        Object name : {}
        <br>
    """.format(eventName, bucketName, objectName)
    
    send = {"Subject": {"Data": eSubject}, "Body": {"Html": {"Data": eBody}}}
    result = bClient.send_email(Source= "[email protected]", Destination= {"ToAddresses": ["[email protected]"]}, Message= send)
    
    return {
        'statusCode': 200,
        'body': json.dumps(result)
    }

About

DEPI DevOps Bootcamp - aws lab

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published