The project includes a Makefile that provides convenient shortcuts for common operations. This guide explains how to use each command and when to use them.
Description: Shows all available commands with descriptions
make helpOutput:
Serverless Todo API - Available Commands
========================================
help Show this help message
init Initialize Terraform
plan Plan Terraform deployment
package Create Lambda deployment package
deploy Deploy the infrastructure
destroy Destroy the infrastructure
test Test the API (requires API URL as parameter)
format Format Python code
lint Lint Python code
clean Clean up temporary files
Description: Initialize Terraform in the terraform directory
make initWhat it does:
- Downloads required Terraform providers
- Initializes the Terraform working directory
- Sets up backend configuration
When to use: First time setup or after adding new providers
Description: Show what Terraform will do without making changes
make planWhat it does:
- Analyzes current state vs desired state
- Shows what resources will be created, modified, or destroyed
- Validates configuration without applying changes
When to use: Before deploying to review changes
Description: Create the Lambda deployment package
make packageWhat it does:
- Zips the Lambda function code and dependencies
- Calculates SHA256 hash for Terraform
- Places package in
terraform/lambda_function.zip
When to use: When you modify Lambda code or dependencies
Description: Deploy the complete infrastructure
make deployWhat it does:
- Creates Lambda package (if needed)
- Runs Terraform apply
- Deploys all AWS resources
- Shows API Gateway URL
When to use: To deploy the complete application
Description: Destroy all infrastructure resources
make destroyWhat it does:
- Removes all AWS resources
- Deletes Lambda function, API Gateway, DynamoDB table
- Cleans up IAM roles and policies
When to use: To clean up and avoid charges
Description: Test the API endpoints
make test API_URL=https://your-api-gateway-url/devWhat it does:
- Tests all API endpoints (GET, POST, DELETE)
- Creates sample tasks
- Verifies CRUD operations
- Shows test results
When to use: After deployment to verify functionality
Example:
make test API_URL=https://1707r6jcga.execute-api.us-east-1.amazonaws.com/devDescription: Format Python code using Black
make formatWhat it does:
- Formats all Python files in the project
- Ensures consistent code style
- Uses Black formatter
When to use: After writing or modifying Python code
Description: Lint Python code using flake8
make lintWhat it does:
- Checks Python code for style issues
- Identifies potential problems
- Ensures code quality
When to use: Before committing code
Description: Clean up temporary files
make cleanWhat it does:
- Removes Python cache files
- Deletes compiled Python files
- Removes Lambda deployment package
When to use: To clean up project directory
make init
make plan
make deploymake format
make lint
make package
make plan
make deploymake test API_URL=https://your-api-url/devmake destroy
make cleanBefore using the Makefile, ensure you have:
- AWS Credentials: Configured via
aws configureor environment variables - Terraform: Installed and available in PATH
- Python: Installed with required packages
- Zip: Available for Lambda package creation
-
Permission Denied
chmod +x scripts/*.sh -
Terraform Not Found
- Install Terraform: https://www.terraform.io/downloads.html
-
AWS Credentials Not Found
aws configure # or export AWS_ACCESS_KEY_ID="your-key" export AWS_SECRET_ACCESS_KEY="your-secret"
-
Python Dependencies Missing
pip install black flake8 requests
To see detailed output, you can run commands directly:
# Instead of make deploy
./scripts/deploy.sh
# Instead of make destroy
./scripts/cleanup.shTo add a new command to the Makefile:
new-command: ## Description of the new command
@echo "Running new command..."
# Your command hereYou can modify any command by editing the Makefile. For example, to change the Python formatter:
format: ## Format Python code
find . -name "*.py" -exec autopep8 --in-place {} \;- Always run
make planbeforemake deploy - Use
make testafter deployment - Run
make formatandmake lintbefore committing - Use
make destroyto avoid ongoing charges - Check
make helpfor available commands
The Makefile commands can be used in CI/CD pipelines:
# Example GitHub Actions workflow
- name: Deploy Infrastructure
run: |
make init
make plan
make deploy
- name: Test API
run: |
make test API_URL=${{ secrets.API_URL }}