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 install
infunctions
to install the dependencies - Run
npm run build
infunctions
to build the code - Run
terraform init
incloud
to initialize Terraform - Run
terraform apply
incloud
to 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/src
directory and runnpm run build
to build the code. - In the
cloud/api.tf
file, add a new function in thelocals.functions
block. - Then run
terraform apply
to deploy the new function.
- Update the lambda function in the
functions/src
directory and runnpm run build
to build the code. - Run
terraform apply
to update the function.
- In the
cloud/api.tf
file, remove the function from thelocals.functions
block. - Run
terraform apply
to 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.