Creating a set of API endpoints to manage office-related data for an organization.
API is developed using Python (AWS Lambda without any framework) and hosted on AWS Lambda. Using Amazon DynamoDB to access database.
Amazon DynamoDB is a fully managed NoSQL database service that provides fast and predictable performance with seamless scalability. We can use Amazon DynamoDB to create a database table that can store and retrieve any amount of data, and serve any level of request traffic. Amazon DynamoDB automatically spreads the data and traffic for the table over a sufficient number of servers to handle the request capacity specified by the customer and the amount of data stored, while maintaining consistent and fast performance.
Table1: office_data id : String (Partition key) name : String location :String Table2: office_transactions officeid : String (Partition key) amount : Number transactionType : String
Amazon API Gateway lets developers connect non-AWS applications to AWS back-end resources. It is a fully managed service that makes it easy for developers to create, publish, maintain, monitor, and secure APIs at any scale. APIs act as the "front door" for applications to access data, business logic, or functionality from your backend services.
A RESTful API is an architectural style for an application programming interface that uses HTTP requests to access and use data. That data can be used to GET , PUT , POST and DELETE data types, which refers to reading, updating, creating and deleting operations related to resources.
- office:
- offices: -> transaction
- status:
Deploying API staging it as officedata to invoke the Staging URL: https://qrba02lwn4.execute-api.ap-south-1.amazonaws.com/officedata
AWS Lambda is a serverless, event-driven compute service that lets us run code for virtually any type of application or backend service without provisioning or managing servers. It lets us automatically run code in response to many types of events, such as HTTP requests from the Amazon API gateway, table updates in Amazon DynamoDB, and state transitions.
Deploying the lamda_function.py on the code Source
Endpoint: /offices
HTTP Method: POST
Functionality: Retrieves all office records.
Edge Cases and Validations:
* When there is no Office
Endpoint: /office
HTTP Method: POST
Input:
{
"id" : "1",
"name" : "Head Office",
"location" : "New York"
}
Request Body: Json containing office details.
Functionality: Creates a new office.
Endpoint: /offices
HTTP Method: PATCH
Input:
{
"id" : "1",
"updateKey" : "name",
"updateValue" : "NewofficeName"
}
Path Parameter : office
Request Body : Json containing updated office details.
Functionality: Updates an existing office.
Endpoint: /offices
HTTP Method: DELETE
Functionality: Deletes an existing office.
Edge Cases and Validations:
* Validating that the officeId exists before attempting a delete and Handle scenarios where the officeId does not exist.
Endpoint: /offices/transactions
HTTP Method: POST
Request Body: Json containing the transaction details.
Functionality: Creates a new office transaction.
Edge Cases and Validations:
* Ensure that the amount is a positive number.
*Validate that the transactionType is either EXPENSE or INCOME .