Search code examples
amazon-web-servicesterraform

How Errors can be handled in Terraform?


I am trying to deploy a lambda function in AWS cloud. I would like to know if an error occurs during deploying the function. Are there any ways using Terraform that we can revert to the older version of the function? For Ex: If v 1.2 of some lambda function code is failed due to some folder structure change or some other issue, it should move to v 1.1 of lambda function.


Solution

  • Terraform alone cannot do this, but you can use Terraform as part of a deployment pipeline for your Lambda functions where the system that is running Terraform passes a Lambda function version to be deployed. Then rolling back is implemented by re-running Terraform with the previous version number.

    There is more information on this (and on deploying Lambda functions with Terraform in general) in the official guide Serverless Applications with AWS Lambda and API Gateway. Even if you are not using API Gateway, the Lambda-related portions of this guide are still relevant.