This is a template for simple serverless lambda functions. It uses Terraform to manage the infrastructure and AWS Lambda to run the code.
- Install the prerequisites
- Run
npm installinfunctionsto install the dependencies - Run
npm run buildinfunctionsto build the code - Run
terraform initincloudto initialize Terraform - Run
terraform applyincloudto create the infrastructure
The terraform apply command will output the Lambda Function URLs. You can use this URL to make requests to the lambda function.
- Simply add new lambda functions in the
functions/srcdirectory and runnpm run buildto build the code. - In the
cloud/api.tffile, add a new function in thelocals.functionsblock. - Then run
terraform applyto deploy the new function.
- Update the lambda function in the
functions/srcdirectory and runnpm run buildto build the code. - Run
terraform applyto update the function.
- In the
cloud/api.tffile, remove the function from thelocals.functionsblock. - Run
terraform applyto delete the function.
In the cloud/api.tf file, you can modify the function configuration in the locals.functions block. If you want to change the function name, memory size, timeout, or environment variables, you can do so in this block. For other configurations, you can modify the aws_lambda_function resource.
In the cloud directory, you can modify the main.tf file to customize the infrastructure configuration. You can update the project name, region, and other configurations in this file.
You can use Terraform workspaces to manage different environments. For example, you can create a prod workspace and a dev workspace. You can then use the terraform workspace select command to switch between the environments. The AWS resources will be tagged and named based on the workspace name.
This project is licensed under the MIT License - see the LICENSE file for details.