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:

  1. It is triggered by S3 events, including object creation, object update, and object deletion in TestBucket.
  2. Whenever it is triggered, it computes the total size of all objects in TestBucket.
  3. 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 TestBucket in 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.
  • scan is 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:

  1. Create an object assignment1.txt in TestBucket with content "Empty Assignment 1" so its size is 19 bytes.
  2. Update assignment1.txt with content "Empty Assignment 2222222222" so its size is 28 bytes.
  3. Delete assignment1.txt, so the bucket size returns to 0.
  4. Create an object assignment2.txt in the bucket with content "33" so its size is 2 bytes.
  5. Sleep between operations so the dots in the plot are not too close to each other.
  6. 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

  1. Clean up all relevant AWS resources before the demo. You may keep your matplotlib Lambda 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.
  2. Run the Python script from Part 1. The TAs should verify that the S3 bucket and DynamoDB table exist and are empty.
  3. 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.
  4. Create the plotting Lambda manually in the AWS console using your submitted handler code. You may use an existing matplotlib Lambda layer or create a new one.
  5. Create the REST API manually in the AWS console.
  6. Create the driver Lambda. You are allowed to update the REST API URL in the code.
  7. Manually invoke the driver Lambda in the AWS console. The TAs will check the DynamoDB contents and the generated plot.
  8. Answer code questions if time permits.