- Creating REST API in Python3 using Flask
- Ran the REST API local 'district_id': args['district_id'], 'dist_name': args['dist_name'], 'stores': storesly.
- Containerized the REST API
- Created Dockerfile
- Built Docker Image
- Ran Docker Container
- Created ECR repository using Python3 Boto3 and pushed Docker Image to ECR
- Created EKS cluster and Node groups
- Created Kubernetes Deployments and Services using Python3
- AWS: EKS, ECR
- Programmatic access and AWS configured with CLI
- Python3
- Python Boto3
- Docker and Kubectl installed
- Code editor (VScode)
- (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.
- (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.
- (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.
- (challenge) Worked on degugging (over 8hrs) why the REST API wouldn't push to the ECR on AWS.
- 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 🥴.
- (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.
Clone the code from the repository:
git clone berlin_store_locator_api
pip3 install -r requirements.txt
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/ on your browser to access the application.
This will start the Flask server in a Docker container on localhost:5000
. Navigate to http://localhost:5000/ on your browser to access the application.
- Once this file is executed by running “python3 eks.py” deployment and service will be created.
- Confirm by running following commands:
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
kubectl port-forward service/<service_name> 5000:5000