This project is a serverless application that provides an API to retrieve movie information stored in a DynamoDB table. The API has two serverless functions:
GetMovies
: Returns all movies in the database.GetMoviesByYear
: Returns a list of movies released in a specified year.
Each movie has associated metadata such as its title, genre, rating, and a URL to its cover image hosted in S3 cloud storage.
If you want to upload movie cover images to an S3 bucket, you can use the file upload functionality from one of my previous projects.
S3 File Upload Project
This is a simple Bash script that uploads a local file to an AWS S3 bucket.
- NoSQL Database (DynamoDB): Stores movie metadata including title, year, genre, rating, and a cover image URL.
- Cloud Storage (S3): Stores cover images for each movie.
- Serverless Functions (Lambda): Functions to fetch all movies or movies by a specified year.
- API Gateway: Exposes the Lambda functions as a publicly accessible API.
The project uses the following AWS services:
- DynamoDB for storing movie metadata.
- S3 for storing movie cover images.
- Lambda for handling API requests.
- API Gateway for routing requests to Lambda functions.
The DynamoDB table (Movies
) contains the following attributes:
- year (Partition Key) – String
- title (Sort Key) – String
- genre – String
- rating – String
- cover_url – String (S3 URL for the movie's cover image)
{
"year": "1993",
"title": "Jurassic Park",
"genre": "Adventure/Sci-fi",
"rating": "8.2",
"cover_url": "https://python-project-jp-movie-posters.s3.amazonaws.com/jp1.jpg"
}
URL: /movies
Method: GET
Description: Returns a JSON list of all movies in the database.
[
{
"year": "1993",
"title": "Jurassic Park",
"genre": "Adventure/Sci-fi",
"rating": "8.2",
"cover_url": "https://python-project-jp-movie-posters.s3.amazonaws.com/jp1.jpg"
},
{
"year": "1997",
"title": "The Lost World: Jurassic Park",
"genre": "Sci-fi/Action",
"rating": "6.6",
"cover_url": "https://python-project-jp-movie-posters.s3.amazonaws.com/jp2.jpg"
}
]
URL: /movies?year={year}
Method: GET
Description: Returns a list of movies released in a specific year. The year is provided as a query parameter.
- year (required) – The release year of the movies.
[
{
"title": "Jurassic Park",
"year": "1993",
"genre": "Adventure/Sci-fi",
"rating": "8.2",
"cover_url": "https://python-project-jp-movie-posters.s3.amazonaws.com/jp1.jpg"
}
]
-
If the
year
parameter is missing or empty, the API returns a400 Bad Request
response:{ "error": "Year parameter is required and cannot be blank." }
-
If no movies are found for the given year, the API returns a
404 Not Found
response:{ "message": "No movies found for the year {year}." }
- AWS CLI installed and configured.
- Boto3 installed:
pip install boto3
. - DynamoDB table and S3 bucket set up.
-
DynamoDB Setup
Run thedynamodb_setup.py
script to create the DynamoDB table and populate it with movie data:python dynamodb_setup.py
-
Deploy Lambda Functions
Deploy the Lambda functions forGetMovies
andGetMoviesByYear
through the AWS Lambda Console or using the AWS CLI. -
API Gateway
Set up API Gateway to expose the Lambda functions as API endpoints.
To make the Lambda functions accessible via HTTP requests, you'll need to set up an API Gateway. Here's how you can do it:
-
Create a New API
- Log in to your AWS Management Console.
- Go to API Gateway and click Create API.
- Choose HTTP API for a simpler setup or REST API for more features (the setup is similar for both).
-
Configure API Routes
- Add a route for the
GetMovies
function:- HTTP method:
GET
- Path:
/movies
- HTTP method:
- Add a route for the
GetMoviesByYear
function:- HTTP method:
GET
- Path:
/movies?year={year}
- HTTP method:
- Add a route for the
-
Integrate API with Lambda Functions
- For each route, specify the integration type as Lambda Function.
- Choose the appropriate Lambda function (
GetMovies
orGetMoviesByYear
). - Ensure that you grant API Gateway permission to invoke your Lambda function by adding the appropriate role or policy.
-
Deploy the API
- Click Deploy and give your deployment a stage name, like
dev
orprod
. - After deployment, you'll get an API endpoint URL that can be used to access your Lambda functions.
- Click Deploy and give your deployment a stage name, like
-
Testing the API
- Open a browser or use a tool like
curl
to test the API.- Example request for all movies:
curl -X GET "https://your-api-id.execute-api.region.amazonaws.com/dev/movies"
- Example request for movies by year:
curl -X GET "https://your-api-id.execute-api.region.amazonaws.com/dev/movies?year=1993"
- Example request for all movies:
- Open a browser or use a tool like
To add an extra layer of security, you can integrate API Gateway with AWS IAM, Lambda authorizers, or API keys to restrict access to your API.
- Add additional search functionality, such as querying an AI API for movie summaries.
- Integrate user authentication for secured access to the API.
This project is licensed under the MIT License.