Skip to content

MihaiBogdanEugen/how-to-serverless-with-aws-part1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

How to Serverless with AWS - Part 1

This is Part 1 in a series of 3 workshops on how to build Serverless applications using AWS Technologies

Part 2

Part 3

Prerequisites

Introduction

Movies is a fictional application used for the management of movies.

Data Models

Movie Info

Property Type
movie_id String
name String
country_of_origin String
release_date String

Movie Rating

Property Type
movie_id String
rotten_tomatoes_rating Number
imdb_rating Number

Data Flows

  • batch ingestion: periodically, a new file is uploaded to the S3 bucket, containing all Movie Info objects
  • single update: occasionally, ratings (a Movie Rating object) are updated
  • data retrieval: frequently, a full Movie model is retrieved

Architecture

Movies Architecture

AWS Technologies

  • Serverless, event-driven, stateless compute workloads
  • Lightweight, limited execution time, resource-bound
  • Works best as "glue" between other stateless AWS services
  • Highly performant, Key-Value and Document NoSQL Data Store
  • Serverless, automatically scalable
  • Supports ACID transactions
  • Simple and secure object storage
  • Serverless & stateless
  • Object management supports event notifications
  • Basic API Gateway, translates events from "web" protocols (HTTP, WebSockets, etc.) into AWS events
  • Fully managed service

Others

  • AWS IAM - secures access to AWS services and resources
  • AWS CloudWatch - logging and monitoring for AWS services
  • AWS X-Ray - tracing for AWS services

Action Plan

  1. Create the DynamoDB tables, note down their names
  2. Create the S3 buckets, note down their name
  3. Create the IAM Policies using the values from 1. and 2.
  4. Create the IAM Roles for lambda.amazonaws.com trusted entities, using the previously defined policies
  5. Package the AWS Lambdas into zip archives using the package make target
  6. Create AWS Lambdas used the packages generated at 5., the roles defined at 4.
  7. Configure AWS Lambdas with proper environment variables, memory settings and tracing
  8. Create an API Gateway
  9. Add required resources for route movies/{movieId}
  10. Add get method with AWS Lambda Proxy integration for specific lambda
  11. Add patch method with AWS Lambda Proxy integration for specific lambda
  12. Create a deployment for the API Gateway
  13. Add S3 bucket integration for specific lambda

Test

  • Generate input test file:
cat movie-infos.csv
mv1,Interstellar,United States,2014-10-26
mv2,The Dark Knight Rises,United States,2012-07-16
mv3,The Prestige,United Kingdom,2006-10-17
  • Upload file to S3 bucket
aws s3 cp ~/movie-infos.csv s3://${bucket_name}
  • Send PATCH request
curl --request PATCH \
  --url ${API_GW_DEPLOYMENT_URI}/movies/mv1 \
  --header 'content-type: application/json' \
  --data '{
	"movie_id": "mv1",
	"rotten_tomatoes_rating": 98,
	"imdb_rating": 43
}'
  • Send GET request, verify results
curl --request GET \
  --url ${API_GW_DEPLOYMENT_URI}/movies/mv1