This project is a python interview challenge written for Rakya Soft co.
To Whom It May Concern:
App is currently deployed and ready to use:
To POST -> https://24uj7roji0.execute-api.us-east-1.amazonaws.com/dev/api/devices/
To GET -> https://24uj7roji0.execute-api.us-east-1.amazonaws.com/dev/api/devices/id7
Make sure your python version is 3.10
- Clone the repository:
git clone https://github.com/HosseinKoofi/raykaAPIChallenge.git
cd raykaAPIChallenge
- Make a virtual environment and activate it:
python -m venv env
.\env\Scripts\activate
- Install requirement dependencies:
cd rayapi
pip install -r requirements.txt
-
Fill the required environment variables:
-
Rename the '\rayapi\.env_sample' file to '.env'
-
Generate and Insert a django secret key
-
Insert Dynamodb table name
-
-
Configure your AWS credentials:
aws configure
- Note: Default output format [None]: json
To run your django app locally:
python manage.py runserver
To run tests, run the following command:
python manage.py test
Test cases are based on APITransactionTestCase of the rest framwork which will use atomic blocks to wrap tests in transactions and allow the test runner to roll back the database at the beginning of each test, allowing easy atomic testing of database related actions, in simple words test data would NOT stay in the database by using APITransactionTestCase.
To run manual tests you are advised to use API test platforms like Postman, also you are able to use rest framework view simply by using the two available urls:
POST -> 'SERVER_ADDRESS/api/devices/'
GET -> 'SERVER_ADDRESS/api/devices/id<int:pk>'
GET /api/devices/id<int:pk>
Parameter | Description |
---|---|
pk |
Required. Id of item to fetch |
POST /api/devices
To deploy this project first make sure Zappa is installed on your virtual environment by
pip freeze
if not then you can install it simply:
pip install zappa
then go ahead and run the following command which helps you to create and configure your new Zappa deployment settings:
zappa init
after runnig the above command you should see a .json file on your project root, Next command is to make your project server-less (deploy it on aws lambda service):
zappa deploy
You will get your url after deployment is done.
Note:
A) You do not have to make a s3 bucket since zappa is able to make one for your project.
B) Zappa will use your aws cli configs in order to connect to aws.
C) There is unexpected bug in urllib3 which perevnts the deployment process to success, in order to defeat it please make sure urllib3 installed version is under 2 (urllib3<2).
-
Django REST framework is a powerful and flexible toolkit for building Web APIs.It has many awesome features such as serialization, validation and handling required responses.
-
PynamoDB is a Pythonic interface for Amazon's DynamoDB which makes it very convenient to create a model that describes your DynamoDB table.
-
AWS CLI is a unified tool to manage your AWS services. The main and only goal of using this module in this project is to configure aws credentials which is mandatory for PynamoDB and Zappa to work.
-
Zappa makes it super easy to build and deploy server-less, event-driven Python applications on AWS Lambda + API Gateway.