Skip to main content
Knowledge Base

Terraform and Gruntwork for Serverless

Answer

Does Gruntwork have any general guidance on how I can leverage my subscription and RefArch to build serverless apps? --- <ins datetime="2022-07-16T00:54:26Z"> <p><a href="https://support.gruntwork.io/hc/requests/108998">Tracked in ticket #108998</a></p> </ins>

We don't have an explicit guide on how to leverage the serverless modules in `terraform-aws-lambda` with your Reference Architecture. We hope to have some examples we can offer in the near future, but for the moment we don't have anything we can share. In the meantime, the general approach we recommend for serverless apps in the Reference Architecture is as follows: - Use [container based lambda functions](https://docs.aws.amazon.com/lambda/latest/dg/images-create.html). This allows you to separate the build and packaging steps from Terraform in a clean way. - Create a CI/CD pipeline on the application code such that a new container image is created in reaction to updates to the code. A general practice you can follow is to build a new image on every commit on the default branch (`main` or `master`) tagged with the commit SHA, and then to build a new image tagged with the release tag on every release. Note that you will want this pipeline to push the container image to ECR at the completion so that it can be deployed. - Once the container is built and pushed to ECR, use the [lambda](https://github.com/gruntwork-io/terraform-aws-service-catalog/tree/master/modules/services/lambda) module from the Service Catalog to deploy the image as a lambda function. Since we don't have an example, refer to the general guidelines in [this knowledge base post](https://github.com/gruntwork-io/knowledge-base/discussions/360) for how to deploy a service catalog module without an explicit example.