Build a cloud app that plots the change in the size of an S3 bucket, following a microservice architecture.
You need to write three Lambda functions:
- a driver Lambda
- a size-tracking Lambda
- a plotting Lambda
You also need:
- an S3 bucket called
TestBucket - a DynamoDB table called
S3-object-size-history
Part 1: Create AWS Resources from Your Laptop
Write a Python program on your laptop that creates:
- the S3 bucket
TestBucket - the DynamoDB table
S3-object-size-history
The attributes and indexes of the table are up to your design, but your table should support storing size information for multiple buckets, not just TestBucket.
Part 2: Size-Tracking Lambda
Write a Lambda function that does the following:
- It is triggered by S3 events, including object creation, object update, and object deletion in
TestBucket. - Whenever it is triggered, it computes the total size of all objects in
TestBucket. - It writes the computed total size into
S3-object-size-history, together with:- the timestamp
- the total number of objects
- the bucket name
Part 3: Plotting Lambda
Write a Lambda function that does the following when triggered:
- Plot the change of the bucket size of
TestBucketin the last 10 seconds. - Add a line indicating the maximum size any bucket has ever reached, based on all items in the table, not just the last 10 seconds.
Requirements for the plot:
- Y-axis: size
- X-axis: timestamp
- Style is not important
Important constraints:
- The plotting Lambda should query items from the table.
scanis not allowed.
You may use matplotlib:
The generated plot should be stored as an object called plot in TestBucket.
You should also expose a REST API from the plotting Lambda so it can be called synchronously.
Part 4: Driver Lambda
Write a driver Lambda that performs the following actions in order:
- Create an object
assignment1.txtinTestBucketwith content"Empty Assignment 1"so its size is 19 bytes. - Update
assignment1.txtwith content"Empty Assignment 2222222222"so its size is 28 bytes. - Delete
assignment1.txt, so the bucket size returns to 0. - Create an object
assignment2.txtin the bucket with content"33"so its size is 2 bytes. - Sleep between operations so the dots in the plot are not too close to each other.
- Finally, call the plotting Lambda API.
The driver Lambda can be invoked manually in the AWS console, and the plot can be downloaded manually from the bucket.
Demo Steps
- Clean up all relevant AWS resources before the demo. You may keep your
matplotlibLambda layer. Download your submission and sync it to your last commit before the deadline. You may not debug during the demo. If you run over time, you may be penalized. - Run the Python script from Part 1. The TAs should verify that the S3 bucket and DynamoDB table exist and are empty.
- Create the size-tracking Lambda manually in the AWS console using your submitted handler code. Set permissions and event triggering. There is nothing to check at this step.
- Create the plotting Lambda manually in the AWS console using your submitted handler code. You may use an existing
matplotlibLambda layer or create a new one. - Create the REST API manually in the AWS console.
- Create the driver Lambda. You are allowed to update the REST API URL in the code.
- Manually invoke the driver Lambda in the AWS console. The TAs will check the DynamoDB contents and the generated plot.
- Answer code questions if time permits.