Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sandramsc/berlin_store_locator_api
RESTful API containing store details and product prices across various districts in Berlin, enabling easy comparison of prices and locations for convenient shopping (synthetic data).
https://github.com/sandramsc/berlin_store_locator_api
Last synced: 7 days ago
JSON representation
RESTful API containing store details and product prices across various districts in Berlin, enabling easy comparison of prices and locations for convenient shopping (synthetic data).
- Host: GitHub
- URL: https://github.com/sandramsc/berlin_store_locator_api
- Owner: sandramsc
- Created: 2024-04-21T21:36:20.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-06-01T09:28:41.000Z (5 months ago)
- Last Synced: 2024-06-03T20:11:17.477Z (5 months ago)
- Language: Python
- Homepage:
- Size: 96.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# **Cloud Native REST API in Python on K8s**
## Development Process
1. Creating REST API in Python3 using Flask
2. Ran the REST API local 'district_id': args['district_id'],
'dist_name': args['dist_name'],
'stores': storesly.
3. Containerized the REST API
1. Created Dockerfile
2. Built Docker Image
3. Ran Docker Container
4. Created ECR repository using Python3 Boto3 and pushed Docker Image to ECR
5. Created EKS cluster and Node groups
6. Created Kubernetes Deployments and Services using Python3## Try the API
[berlin_store_locator_api](https://berlin-store-locator-api.onrender.com)
### How to view the API fields:
1. [Show all districts](https://berlin-store-locator-api.onrender.com/districts/all)
2. [Show all stores](https://berlin-store-locator-api.onrender.com/stores/all)
3. [Show all products](https://berlin-store-locator-api.onrender.com/products/all)## **Tools & technologies used in this project**
- [x] AWS: EKS, ECR
- [x] Programmatic access and AWS configured with CLI
- [x] Python3
- [x] Python Boto3
- [x] Docker and Kubectl installed
- [x] Code editor (VScode)## Challenges & Take away
- [x] (challenge) I chose to create this REST API because a CLI tool I am building needs an API of this structure, after some research conducted, trying to find one that had the structure and data I needed, I chose to build one after not finding an exact fit for my requirements. The most challenging aspect was figuring out how to create nested fields (so they'd render in the UI via code as they do in the JSON file) and test the requests so they were all successfull.
- [x] (challenge) Since this API had a store field and a products field that were alll nested under the districts field, I needed to figure out a function that would enable users to GET, PUT, PATCH to any one field if they so desired to, this in part was tied to finding a solution to list the resource fields and then calling these in their respective requests. This took a couple of days and at the moment only the test for the PUT request is working as it should.
- [x] (take away) It's a great thing that I am enjoying the processes of developing this tool as the challenges did certainly cause moment for pause and reconsideration in the wee hours of 4am when debugging and trying to find a fix unittests for the requests. It tought me that resiliance and consistency in working on a project project you enjoy is worth the challenge (and to take short breaks between debugging, helps with re-focusing and looking at the bug from different perspctives, which aided with finding a solution) and I learned how to create resources for netsed fields.----------
- [x] (challenge) Worked on degugging (over 8hrs) why the REST API wouldn't push to the ECR on AWS.
I had already:- added access_id
- added access_key
- added region
- logged in successfully
- built the image
- added a tag
yet the image still wouldn't push. I'd also given the IAM user these permissions:- AdministratorAccess
- AmazonEC2ContainerRegistryFullAccess
- AWSAppRunnerServicePolicyForECRAccess
- IAMUserChangePassword***Most StackOverflow, GitHub related posts suggested to add the above in different ways, initially none would work for several hours π₯΄.
- [x] (take away) The challenge with ECR pushing underscored the intricacies of AWS IAM permissions and Docker interactions. This experience emphasized the need for careful consideration of AWS configurations and troubleshooting strategies, showcasing the importance of perseverance and resourcefulness in resolving technical hurdles.
## **Part 1: Deploying the Flask application locally**
### **Step 1: Clone the code**
Clone the code from the repository:
```
git clone berlin_store_locator_api
```### **Step 2: Install dependencies**
```
pip3 install -r requirements.txt
```### **Step 3: Run the application**
To run the application, navigate to the root directory of the project and execute the following command:
```
python3 app.py
```This will start the Flask server on **`localhost:5000`**. Navigate to [http://localhost:5000/](http://localhost:5000/) on your browser to access the application.
## **Part 2: Dockerizing the Flask application**
### **Step 1: Created a Dockerfile**
### **Step 2: Built the Docker image**
### **Step 3: Ran the Docker container**This will start the Flask server in a Docker container on **`localhost:5000`**. Navigate to [http://localhost:5000/](http://localhost:5000/) on your browser to access the application.
## **Part 3: Pushed the Docker image to ECR**
### **Step 1: Created an ECR repository**
### **Step 2: Push the Docker image to ECR**## **Part 4: Created an EKS cluster and deploying the app using Python**
### **Step 1: Created an EKS cluster**
### **Step 2: Created a node group**
### **Step 3: Create deployment and service**- Once this file is executed by running βpython3 eks.pyβ deployment and service will be created.
- Confirm by running following commands:```jsx
kubectl get deployment -n default (check deployments)
kubectl get service -n default (check service)
kubectl get pods -n default (to check the pods)
```Once the pod is up and running, execute the port-forward to expose the service
```bash
kubectl port-forward service/ 5000:5000
```