{"id":19143174,"url":"https://github.com/devenes/terraform-containerization-bookstore-api","last_synced_at":"2026-04-06T02:33:18.134Z","repository":{"id":107131447,"uuid":"484746974","full_name":"devenes/terraform-containerization-bookstore-api","owner":"devenes","description":"Bookstore Web API Application aims to create a bookstore web service using Docker to have the understanding to dockerization of an application. The application code is to be deployed as a RESTful web service with Flask using Dockerfile and Docker Compose on AWS Elastic Compute Cloud (EC2) Instance using Terraform.","archived":false,"fork":false,"pushed_at":"2022-06-11T10:07:48.000Z","size":640,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-03T14:31:21.074Z","etag":null,"topics":["aws-elastic-compute-cloud","bash","docker","docker-compose","dockerfile","ec2","flask","git","github","http","mysql","python-flask","restful","terraform"],"latest_commit_sha":null,"homepage":"https://devenes.github.io/terraform-containerization-bookstore-api/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devenes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-23T12:53:59.000Z","updated_at":"2023-09-28T11:40:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"3c8e7d91-c295-41f0-8803-0198d6cc6178","html_url":"https://github.com/devenes/terraform-containerization-bookstore-api","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/devenes/terraform-containerization-bookstore-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devenes%2Fterraform-containerization-bookstore-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devenes%2Fterraform-containerization-bookstore-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devenes%2Fterraform-containerization-bookstore-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devenes%2Fterraform-containerization-bookstore-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devenes","download_url":"https://codeload.github.com/devenes/terraform-containerization-bookstore-api/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devenes%2Fterraform-containerization-bookstore-api/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31457708,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-05T21:22:52.476Z","status":"online","status_checked_at":"2026-04-06T02:00:07.287Z","response_time":112,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws-elastic-compute-cloud","bash","docker","docker-compose","dockerfile","ec2","flask","git","github","http","mysql","python-flask","restful","terraform"],"created_at":"2024-11-09T07:29:51.666Z","updated_at":"2026-04-06T02:33:18.118Z","avatar_url":"https://github.com/devenes.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003eContainerization of Python Flask Bookstore Web API with MySQL using Docker Compose and Terraform\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/devenes/terraform-containerization-bookstore-api/actions/workflows/pages/pages-build-deployment/badge.svg\" alt=\"Terraform Containerization Bookstore Api\" /\u003e\n  \u003cimg alt=\"Github top language\" src=\"https://img.shields.io/github/languages/top/devenes/terraform-containerization-bookstore-api?color=blue\"\u003e\n  \u003cimg alt=\"Github language count\" src=\"https://img.shields.io/github/languages/count/devenes/terraform-containerization-bookstore-api?color=pink\"\u003e\n  \u003cimg alt=\"Repository size\" src=\"https://img.shields.io/github/repo-size/devenes/terraform-containerization-bookstore-api?color=orange\"\u003e\n  \u003cimg alt=\"License\" src=\"https://img.shields.io/github/license/devenes/terraform-containerization-bookstore-api?color=red\"\u003e\n  \u003c!-- \u003cimg alt=\"Github issues\" src=\"https://img.shields.io/github/issues/devenes/terraform-containerization-bookstore-api?color=56BEB8\" /\u003e --\u003e\n  \u003c!-- \u003cimg alt=\"Github forks\" src=\"https://img.shields.io/github/forks/devenes/terraform-containerization-bookstore-api?color=56BEB8\" /\u003e --\u003e\n  \u003c!-- \u003cimg alt=\"Github stars\" src=\"https://img.shields.io/github/stars/devenes/terraform-containerization-bookstore-api?color=56BEB8\" /\u003e --\u003e\n\u003c/p\u003e\n\n\u003chr\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"#dart-about\"\u003eAbout\u003c/a\u003e \u0026#xa0; | \u0026#xa0; \n  \u003ca href=\"#sparkles-Case-Study-Details\"\u003eCase Study Details\u003c/a\u003e \u0026#xa0; | \u0026#xa0;\n  \u003ca href=\"#rocket-technologies\"\u003eTechnologies\u003c/a\u003e \u0026#xa0; | \u0026#xa0;\n  \u003ca href=\"#white_check_mark-requirements\"\u003eRequirements\u003c/a\u003e \u0026#xa0; | \u0026#xa0;\n  \u003ca href=\"#checkered_flag-starting\"\u003eStarting\u003c/a\u003e \u0026#xa0; | \u0026#xa0;\n  \u003ca href=\"#memo-license\"\u003eLicense\u003c/a\u003e \u0026#xa0; | \u0026#xa0;\n  \u003ca href=\"https://github.com/devenes\" target=\"_blank\"\u003eAuthor\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cbr\u003e\n\n## :dart: About\n\nBookstore Web API Application aims to create a bookstore web service using Docker to have the understanding to dockerization of an application. The application code is to be deployed as a RESTful web service with Flask using Dockerfile and Docker Compose on AWS Elastic Compute Cloud (EC2) Instance using Terraform.\n\n## Project Architecture\n\n![Project](./readme-content/bookstore-api.png)\n\n## :sparkles: Case Study Details\n\n- Your team has started working on a project to create a `Bookstore` Application as Web Service.\n\n- Software Developers in your team have already developed first version of `Bookstore` application. They have designed a database to keep book records with following fields.\n\n  - book_id: unique identifier for books, type is numeric.\n\n  - title: title of the book, type is string.\n\n  - author: author of the book. type is string.\n\n  - is_sold: book availability status, type is boolean.\n\n- Your teammates also created the RESTful web service as given in [Bookstore API](./bookstore-api.py) using Python Flask Framework. Below table shows how the HTTP methods are designed to affect the given resources identified by URIs.\n\n| HTTP Method | Action                              | Example                                                                                             |\n| ----------- | ----------------------------------- | --------------------------------------------------------------------------------------------------- |\n| `GET`       | Obtain information about a resource | http://[ec2-hostname]/books (retrieves list of all books)                                           |\n| `GET`       | Obtain information about a resource | http://[ec2-hostname]/books/123 (retrieves book with id=123)                                        |\n| `POST`      | Create a new resource               | http://[ec2-hostname]/books (creates a new book, from data provided with the request)               |\n| `PUT`       | Update a resource                   | http://[ec2-hostname]/books/123 (updates the book with id=123, from data provided with the request) |\n| `DELETE`    | Delete a resource                   | http://[ec2-hostname]/books/123 (delete the book with id=123)                                       |\n\n- You are, as a cloud engineer, requested to deploy the app in the development environment on a Docker Machine on AWS EC2 Instance using Terraform to showcase your project. To do that you need to;\n\n  - Get the app code from GitHub repo of your team.\n\n  - Create docker image using the `Dockerfile`.\n\n  - Deploy the app using `docker compose`. To do so;\n\n    - Create a database service using MySQL.\n\n    - Configure the app service to run on `port 80`.\n\n    - Use a custom network for the services.\n\n- In the development environment, you can configure your Terraform config file using the followings,\n\n  - The application should be created with new AWS resources.\n\n  - The application should run on Amazon Linux 2 EC2 Instance\n\n  - EC2 Instance type can be configured as `t2.micro`.\n\n  - Instance launched by Terraform should be tagged `Web Server of Bookstore`\n\n  - The Web Application should be accessible via web browser from anywhere.\n\n  - The Application files should be downloaded from Github repo and deployed on EC2 Instance using user data script within Terraform configuration file.\n\n  - Bookstore Web API URL should be given as output byTerraform, after the resources created.\n\n## :rocket: Technologies\n\nThe following tools were used in this project:\n\n- [Python](https://www.python.org/)\n- [Docker](https://www.docker.com/)\n- [Docker Compose](https://docs.docker.com/compose/overview/)\n- [Terraform](https://www.terraform.io/)\n- [Flask](https://flask.palletsprojects.com/)\n- [AWS](https://aws.amazon.com/)\n\n## :white_check_mark: Requirements\n\nBefore starting :checkered_flag:, you need to have [Git](https://git-scm.com), [Docker](https://www.docker.com/) and [Terraform](https://www.terraform.io/) installed on your machine.\n\n## :checkered_flag: Starting\n\n```bash\n# Clone this project\ngit clone https://github.com/devenes/terraform-containerization-bookstore-api\n\n# Access\ncd terraform-containerization-bookstore-api\n\n# Initialize terraform\nterraform init\n\n# Apply terraform\nterraform apply -auto-approve\n```\n\n- To showcase your projects REST functions, use `curl` command for each HTTP methods namely, `GET`, `POST`, `PUT`, `DELETE`.\n\n![note](./readme-content/note_1.png)\n\n### GET\n\n```bash\ncurl --request GET \\\n--url 'http://ec2-52-91-247-19.compute-1.amazonaws.com/books' \\\n--header 'content-type: application/json'\n```\n\n### POST\n\n```bash\ncurl --request POST \\\n--url 'http://ec2-52-91-247-19.compute-1.amazonaws.com/books' \\\n--header 'content-type: application/json' \\\n--data '{\"author\":\"Paulo Coelho\", \"title\":\"The Alchemist\", \"is_sold\":true}'\n```\n\n```bash\ncurl --request POST \\\n--url 'http://ec2-52-91-247-19.compute-1.amazonaws.com/books' \\\n--header 'content-type: application/json' \\\n--data '{\"author\":\"Gabriel Garcia Marquez\", \"title\":\"One Hundred Years of Solitude\", \"is_sold\":true}'\n```\n\n```bash\ncurl --request POST \\\n--url 'http://ec2-52-91-247-19.compute-1.amazonaws.com/books' \\\n--header 'content-type: application/json' \\\n--data '{\"author\":\"Harper Lee\", \"title\":\"To Kill a Mockingbird\", \"is_sold\":true}'\n```\n\n### PUT\n\n```bash\ncurl --request PUT \\\n--url 'http://ec2-52-91-247-19.compute-1.amazonaws.com/books/3' \\\n--header 'content-type: application/json' \\\n--data '{\"author\":\"Jose Rodrigues dos Santos\", \"title\":\"A Formula de Deus\", \"is_sold\":true}'\n```\n\n### DELETE\n\n```bash\ncurl --request DELETE \\\n--url 'http://ec2-52-91-247-19.compute-1.amazonaws.com/books/2' \\\n--header 'content-type: application/json'\n```\n\n## Expected Outcome\n\n- ### API Service Output\n\n  ![output](./readme-content/output_2.png)\n\n- ### Terraform Outputs\n\n  ![output](./readme-content/output_1.png)\n\n### At the end of the project, following topics are to be covered;\n\n- MySQL Database Configuration\n\n- Bash scripting\n\n- Docker Images\n\n- Docker Compose\n\n- AWS EC2 Service\n\n- AWS Security Group Configuration\n\n- Terraform Configuration with AWS\n\n- Git \u0026 Github for Version Control System\n\n### At the end of the project, you will be able to;\n\n- configure connection to the `MySQL` database.\n\n- build a Docker image.\n\n- configure Docker Compose to run Python Flask app.\n\n- improve bash scripting skills using `user data` section in Terraform to install and setup web application on EC2 Instance\n\n- configure AWS EC2 Instance and Security Groups.\n\n- configure Terraform files to use AWS Resources.\n\n- use git commands (push, pull, commit, add etc.) and Github as Version Control System.\n\n- run the web application on AWS EC2 instance using the GitHub repo as codebase.\n\n## Resources\n\n- [Representational State Transfer](https://en.wikipedia.org/wiki/Representational_state_transfer)\n\n- [Terraform AWS Provider Documentaion](https://registry.terraform.io/providers/hashicorp/aws/latest/docs)\n\n- [Dockerfile](https://docs.docker.com/engine/reference/builder/#dockerfile)\n\n- [Docker Compose](https://docs.docker.com/compose/overview/)\n\n- [Python Image](https://hub.docker.com/_/python)\n\n- [MySQL Image](https://hub.docker.com/_/mysql/)\n\n- [pip Doc](https://pip.pypa.io/en/stable/cli/pip_install/#install-requirement)\n\n- [Flask MySQL](https://flask-mysql.readthedocs.io/en/stable/)\n\n## :memo: License\n\nThis project is under license from MIT. For more details, see the [LICENSE](LICENSE) file.\n\nMade with :heart: by \u003ca href=\"https://github.com/devenes\" target=\"_blank\"\u003edevenes\u003c/a\u003e\n\n\u0026#xa0;\n\n\u003ca href=\"#top\"\u003eBack to top\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevenes%2Fterraform-containerization-bookstore-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevenes%2Fterraform-containerization-bookstore-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevenes%2Fterraform-containerization-bookstore-api/lists"}