Real-time use case to shutdown instances on a daily basis
In the next real-time use case, you will see how you can shut down an instance daily to save costs. This is especially useful in a non-production or development environment to shut down instances, for example, at 9 P.M. (or based on your company policy) to save costs.
So far, the use cases we have looked at have used the AWS console. In this use case, you are going to automate the process using Terraform.
These are the steps you need to follow:
- The first step is to create an IAM role. You need to use a Terraform
aws_iam_role
resource to create a role resource. This policy will give the Lambda function permission to assume the role:"aws_iam_role" "iam_for_lambda" { Â Â name = "iam_for_lambda" Â Â assume_role_policy = <<EOF { Â Â "Version": "2012-10-17", Â Â "Statement": [ Â Â Â Â { Â Â Â ...