The Nuwehack Terraform Cloud Tasker project aims to create a task management system using AWS Lambda functions and a Flask-based API. This system allows users to schedule and manage tasks efficiently. Below, you'll find instructions for setting up the project.
The project is organized into the following directories:
nuwehack-terraform-cloud-tasker/
├── Infraestructure
│ ├── lambda
│ │ ├── create_scheduled_task.py
│ │ ├── list_scheduled_task.py
│ │ ├── execute_scheduled_task.py
│ │ ├── lambda_1.zip
│ │ ├── lambda_2.zip
│ │ ├── lambda_3.zip
│ │ └── README.md
│ └── Terraform
│ ├── main.tf
│ └── policy.json
├── taskapi
│ ├── app.py
│ └── README.md
├── README.md
├── .gitignore
└── requirements.txt
-
Infraestructure
: Contains the infrastructure-related code and configuration.lambda
: This directory holds the AWS Lambda functions. You can find the Lambda functions (create_scheduled_task.py
,list_scheduled_task.py
andexecute_scheduled_task.py
) here.create_scheduled_task.py
: This is the 1st Lambda that creates the task in the DynamoDB tableTasks
.list_scheduled_task.py
: This is the 2nd Lambda that get a list of tasks that are in the DynamoDB tableTasks
.execute_scheduled_task.py
: This is the 3rd Lambda that creates an item in an S3 bucket calledtaskstorage
.lambda_1.zip
: This zip contains a file calledlambda_function.py
that contains the code of the 1st LambdacreateScheduledTask
.lambda_2.zip
: This zip contains a file calledlambda_function.py
that contains the code of the 2nd LambdalistScheduledTask
.lambda_3.zip
: This zip contains a file calledlambda_function.py
that contains the code of the 3rd LambdaexecuteScheduledTask
.README.md
: Provides additional details about the Lambdas and its Usage.
Terraform
: The Terraform configuration for creating the necessary AWS resources. Key files includemain.tf
(defining resources) andpolicy.json
(IAM policy for Lambda functions).
-
taskapi
: Contains the Flask-based API for managing lambda tasks.app.py
: The main Flask application that handles lambda task creation and listing.README.md
: Provides additional details about the API setup and endpoints.
Follow these steps to set up the project:
-
Install Requirements:
- Navigate to the root folder of your project.
- Install the required Python packages:
pip install -r requirements.txt
-
Lambdas Setup:
- Change directory to
Infraestructure/Terraform
:cd Infraestructure/Terraform
- Initialize Terraform:
terraform init
- Plan the infrastructure changes:
terraform plan
- Apply the changes:
terraform apply
- Change directory to
-
TaskAPI Setup:
- Change directory to
taskapi
:cd ../taskapi
- Run the Flask server in debug mode (default port is 5000):
flask run
And you're ready to go!
- Change directory to
-
Create a scheduled task:
awslocal lambda invoke --function-name createScheduledTask --payload '{"task_name": "my task", "cron_expression": "*/5 * * * *"}' output.json
-
List scheduled tasks:
awslocal lambda invoke --function-name listScheduledTask output.json
-
Execute a scheduled task:
awslocal lambda invoke --function-name executeScheduledTask output.json
-
Create a task:
curl --location 'http://127.0.0.1:5000/createtask' \ --header 'Content-Type: application/json' \ --data '{ "task_name": "my task name", "cron_expression": "*/5 * * * *" }'
-
List tasks:
curl --location 'http://127.0.0.1:5000/listtask'
This project was developed by Greiberth Pérez and some cups of coffee😁