Serverless Rest API created at AWS using Terraform
This project was created by Caio Moretti for the AsCan Academy "AWS Iniciante" trail from Instituto Atlântico. I had to create a REST API using IaC and some AWS resources
The API developed in Python using AWS Lambda serverless feature is capable of communicating with a NoSQL database (AWS DynamoDB), allowing for obtaining, registering, modifying, and deleting products through endpoints created by AWS API Gateway. The entire environment was built using an infrastructure-as-code framework called Terraform, meeting all the requirements of the proposed challenge.
Additionally, the API was subjected to automated testing using the PyTest library, ensuring the validation of the functioning of the services offered. It is important to highlight that the performance of tests was not a mandatory requirement of the project but rather an additional feature that was implemented to ensure the quality and reliability of the final product.
There are some tools you will need to run the project correctely:
To use this project, first clone the repo on your device using the command below:
git clone https://github.com/Caio-Moretti/Rest-API-AWS.git
After that, you wil need to configure the AWS Configuration using AWS CLI from the account created.
aws configure [--profile profile-name]
You will need to configure your AWS Account:
AWS Access Key ID [****]:
AWS Secret Access Key [****]:
Default region name [us-west-1]:
Default output format [None]:
For a guide you can access the AWS CLI Command Reference
After that, you will need to run your Terraform files
For that you will need to initialize the terraform repository:
terraform init
After that, you can plan your infrastructure provisioning:
terraform plan -out=plan_out
Lastly, you can apply the plan file:
terraform apply plan_out
This will provission your AWS infrastructure. You can check by login into your AWS Account and accessing the resources created
After provisioning your infra, you can test your API by running test_api.py
First, install PyTest:
pip install pytest
For running your API Tests, you can use the following command on your project terminal:
pytest -v -s
Also, you can use software programs like Postman or Insomnia to test the API functionalities.
- The code runs the terraform folder when the Terraform apply command is used
- Every .tf file is ran at the same time, so some depends_on should be used in the code (see api.tf)
- After modifying any Terraform file you should run all the terraform commands again.
- The test_api.py file is the test file which is run when the PyTest commands are used