12 Weeks AWS Workshop Challenge
Week Nine: Event Driven Architecture
Event Driven Architecture
Event Driven Architecture refers to a responsive design that allows you to configure triggers that will respond to a particular system event.
Example of a Simple Event Driven Architecture
AWS Lambda: Lambda is a core serverless service on AWS. With AWS Lambda, you can run code without provisioning or managing servers.
Amazon Simple Email Service (SES): Amazon SES is a fully managed emailing service.
Amazon Simple Storage Service (S3): Amazon S3 is a fully managed, highly available, and scalable storage service, with a wide range of use cases such as websites, backups, archives, and cloud-native applications.
You can create a Lambda function that will trigger a SES email to be sent to you when an object is uploaded or deleted on your Amazon S3 bucket.
Benefits of Event Driven Architecture
Event Driven Architectures are beneficial when it comes to the management and communication between serverless, loosely coupled, cloud-native microservices applications.
Creating a simple Event Driven Architecture
Do you have a simple EDA?
Yes? Well, that’s cool. See you in my next post then.
No? Ok, no big deal. Let’s create a simple Event Driven Architecture using AWS Lambda, Amazon SES and Amazon S3.
Prerequisites
To create an Event Driven Architecture Using AWS Lambda you will need:
(1) to read this Blog Post: 12 Weeks AWS Workshop Challenge — Week Eight (Serverless) to familiarize yourself with basic Lambda concepts.
(2) an AWS account to configure the resources
(3) an accessible email address to receive SES emails
(4) a text editor
(5) understand basic python3
(6) ability to edit a simple python file
(7) know how to use and navigate AWS SDKs & Documentation
(8) an Amazon S3 bucket in the us-east-1 (N. Virginia) region
(9) an image to upload into the bucket. (save it as Lambda.png)
Step by Step Guide
Create SES Verified Identity
- Login to the AWS Management Console using your IAM user name.
- You will be using the US East (N. Virginia) us-east-1 region. So, on the top right navigation bar, make sure N. Virginia is selected.
- On the top left corner, click on the Services button.
- Select Business Applications on the left side of the drop down menu.
- Select Amazon Simple Email Service.
- Under Configurations, Click Verified Identities.
- Click Create identity.
- Identity type: Email address.
- Email address: Enter your email address.
- Click Create identity.
- Identity status: Verification pending.
- Navigate to your email client.
- Click on the link to authorize your email address.
- Congratulations! You have successfully verified an email address. You can now start sending email from this address.
- Navigate back to SES. Identity status: Verified.
Create an Amazon S3 Bucket
- On the top left corner, click on the Services button.
- Select Storage on the left side of the drop down menu.
- Select S3.
- Click the Create bucket button.
- AWS Region: US-East (N. Virginia) us-east-1.
- Bucket name: your-unique-bucket-name. Amazon S3 bucket names must be globally unique, so make sure you choose a globally unique name.
- Object ownership: ACLs disabled (recommended).
- Block Public Access settings for this bucket: make sure Block all public access is checked.
- Bucket Versioning: Disable.
- Leave everything as default and click Create bucket.
- Click on the Bucket name you just created.
- Click Close.
Create a Lambda Function
- Your bucket and your Lambda function must be in the same region. On the top right navigation bar, make sure N. Virginia is selected.
- On the top left corner, click on the Services button.
- Select Compute on the left side of the drop down menu.
- Select Lambda.
- Click Create a function.
- Select Use a blueprint.
- Blueprint name: Get S3 object (python3.10)
- Function name: myEventFunction.
- Execution role: Create a new role from AWS policy templates.
- Role name: myEventRole.
- Policy templates — optional: Amazon S3 read only permissions and Amazon SES bounce permissions.
- Lambda function code: Peruse and leave as default.
- S3 Trigger. Bucket: select your bucket.
- Event Types: Select All object create events and All object delete events.
- Prefix — optional: Leave unchecked.
- Suffix — optional: Leave unchecked.
- Recursive invocation: Check the acknowledgement.
- Click Create function.
- Congratulations! Your function is created.
- On the top left corner, click on the Services button.
- Select Security, Identity & Complianceon the left side of the drop down menu.
- Select IAM.
- Click Roles.
- Click myEventRole.
- Click Add permissions: Attach policies.
- Search and check: AmazonSESFullAccess.
- Click Add permissions.
- Navigate to the following AWS Documentation: Sending an email through Amazon SES using an AWS SDK.
- Select Python and paste the code to your text editor.
- Follow the instructions on the template.
- Sender: Your details.
- Recipient: Your email address.
- CONFIGURATION_SET: Comment it out.
- AWS_REGION: us-east-1
- SUBJECT: Event Driven Architecture Notification
- BODY_TEXT: Leave as default
- BODY_HTML: Leave as default
- CHARSET: Leave as default
- client: Leave as default
- Comment out: ConfigurationSetName=CONFIGURATION_SET
- Leave everything as default and copy the contents of the file.
- Navigate back to your Lambda function.
- Click Code.
- Select the lambda_function.py file.
- Delete everything, and replace it with the contents of the file you just edited.
- Click Deploy.
- Successfully updated the function myEventFunction.
- Navigate to your Amazon S3 bucket: Upload a file.
- Check your emails. You should receive the Event Driven Architecture Notification.
- Congratulations! You have created a simple Event Driven Architecture.
Important: Clean Up Resources
Don’t get a Bill Shock by leaving unnecessary resources running, because as from the 1st of February 2024, AWS has started charging for IP addresses.
- Navigate back to AWS Lambda.
- Click Functions.
- Check myEventFunction.
- Click Delete.
- Type delete and confirm deletion.
- Click Close.
- Navigate to your Amazon S3 Bucket.
- Delete unnecessary objects in your bucket or delete your bucket if you specifically created one for this tutorial.
End of Step by Step Guide
Conclusion
Congratulations! In this Step by Step Guide, you created an AWS Lambda function that responds to object uploads and deletions on an Amazon S3 bucket, and sends an email notification using Amazon SES.
…And theoretically, you understand the basics of event driven architecture. The more you work with microservices, you will configure more complex event driven monitoring and notification systems.
Blog Post Summary
Theory
Introduction to Event Driven Architecture.
Practical
Creating a simple Event Driven Architecture using AWS Lambda, Amazon SES and Amazon S3.