Stop and start instance, rds resources and autoscaling groups with lambda function.
For Terraform 0.15 use version v3.* of this module.
If you are using Terraform 0.11 you can use versions v1.*.
- Aws lambda runtine Python 3.7
- ec2 instances scheduling
- ecs service scheduling
- rds clusters scheduling
- rds instances scheduling
- redshift clusters scheduling
- documentdb clusters scheduling
- autoscalings scheduling
- cloudwatch alarm scheduling
- Aws CloudWatch logs for lambda
module "stop_ec2_instance" {
source = "diodonfrost/lambda-scheduler-stop-start/aws"
name = "ec2_stop"
cloudwatch_schedule_expression = "cron(0 0 ? * FRI *)"
schedule_action = "stop"
autoscaling_schedule = "false"
documendb_schedule = "false"
ec2_schedule = "true"
ecs_schedule = "false"
rds_schedule = "false"
redshift_schedule = "false"
cloudwatch_alarm_schedule = "false"
scheduler_tag = {
key = "tostop"
value = "true"
}
}
module "start_ec2_instance" {
source = "diodonfrost/lambda-scheduler-stop-start/aws"
name = "ec2_start"
cloudwatch_schedule_expression = "cron(0 8 ? * MON *)"
schedule_action = "start"
autoscaling_schedule = "false"
documendb_schedule = "false"
ec2_schedule = "true"
ecs_schedule = "false"
rds_schedule = "false"
redshift_schedule = "false"
cloudwatch_alarm_schedule = "false"
scheduler_tag = {
key = "tostop"
value = "true"
}
}
- Autoscaling scheduler - Create lambda functions to suspend autoscaling group with tag
tostop = true
and terminate its ec2 instances on Friday at 23:00 Gmt and start them on Monday at 07:00 GMT - Documentdb scheduler - Create lambda functions to stop documentdb cluster with tag
tostop = true
on Friday at 23:00 Gmt and start them on Monday at 07:00 GMT - Instance scheduler - Create lambda functions to stop ec2 with tag
tostop = true
on Friday at 23:00 Gmt and start them on Monday at 07:00 GMT - Rds aurora - mariadb scheduler - Create lambda functions to stop rds mariadb and aurora cluster with tag
tostop = true
on Friday at 23:00 Gmt and start them on Monday at 07:00 GMT - test fixture - Deploy environment for testing module
Name | Version |
---|---|
terraform | >= 1.0 |
archive | 2.3.0 |
aws | >= 5.94.1 |
Name | Version |
---|---|
archive | 2.3.0 |
aws | >= 5.94.1 |
No modules.
Name | Description | Type | Default | Required |
---|---|---|---|---|
autoscaling_schedule | Enable scheduling on autoscaling resources | any |
false |
no |
autoscaling_terminate_instances | Terminate instances when autoscaling group is scheduled to stop | bool |
false |
no |
aws_regions | A list of one or more aws regions where the lambda will be apply, default use the current region | list(string) |
null |
no |
cloudwatch_alarm_schedule | Enable scheduleding on cloudwatch alarm resources | any |
false |
no |
cloudwatch_schedule_expression | Define the aws cloudwatch event rule schedule expression | string |
"cron(0 22 ? * MON-FRI *)" |
no |
custom_iam_role_arn | Custom IAM role arn for the scheduling lambda | string |
null |
no |
documentdb_schedule | Enable scheduling on documentdb resources | bool |
false |
no |
ec2_schedule | Enable scheduling on ec2 resources | any |
false |
no |
ecs_schedule | Enable scheduling on ecs services | bool |
false |
no |
kms_key_arn | The ARN for the KMS encryption key. If this configuration is not provided when environment variables are in use, AWS Lambda uses a default service key. | string |
null |
no |
name | Define name to use for lambda function, cloudwatch event and iam role | string |
n/a | yes |
rds_schedule | Enable scheduling on rds resources | any |
false |
no |
redshift_schedule | Enable scheduling on redshift resources | any |
false |
no |
resources_tag | DEPRECATED, use scheduler_tag variable instead | map(string) |
null |
no |
runtime | The runtime environment for the Lambda function that you are uploading | string |
"python3.13" |
no |
schedule_action | Define schedule action to apply on resources, accepted value are 'stop or 'start | string |
"stop" |
no |
scheduler_tag | Set the tag to use for identify aws resources to stop or start | map(string) |
{ |
no |
tags | Custom tags on aws resources | map(any) |
null |
no |
Name | Description |
---|---|
lambda_iam_role_arn | The ARN of the IAM role used by Lambda function |
lambda_iam_role_name | The name of the IAM role used by Lambda function |
scheduler_lambda_arn | The ARN of the Lambda function |
scheduler_lambda_function_last_modified | The date Lambda function was last modified |
scheduler_lambda_function_version | Latest published version of your Lambda function |
scheduler_lambda_invoke_arn | The ARN to be used for invoking Lambda function from API Gateway |
scheduler_lambda_name | The name of the Lambda function |
scheduler_log_group_arn | The Amazon Resource Name (ARN) specifying the log group |
scheduler_log_group_name | The name of the scheduler log group |
Some of these tests create real resources in an AWS account. That means they cost money to run, especially if you don't clean up after yourself. Please be considerate of the resources you create and take extra care to clean everything up when you're done!
In order to run tests that access your AWS account, you will need to configure your AWS CLI
credentials. For example, you could
set the credentials as the environment variables AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY
.
# Test basic terraform deployment
cd examples/instance-scheduler
terraform test -verbose
# Test rds scheduler
cd examples/rds-scheduler
terraform test -verbose
Modules managed by diodonfrost
Apache 2 Licensed. See LICENSE for full details.