GithubHelp home page GithubHelp logo

synoa / terraform-aws-lambda-scheduler Goto Github PK

View Code? Open in Web Editor NEW

This project forked from neillturner/terraform-aws-lambda-scheduler

0.0 4.0 0.0 10.68 MB

Stop and start EC2 and RDS instances according to schedule via lambda and terraform

License: Other

HCL 100.00%

terraform-aws-lambda-scheduler's Introduction

terraform-aws-lambda-scheduler

Stop and start EC2 and RDS instances according to schedule via lambda and terraform.

Overview

The scheduler looks at the schedule tag to see if it needs to stop or start and instance. It works by setting a tag (default name schedule) to a string giving the stop and start time hour for each day.

A schedule tag for an EC2 instance is json and looks like:

{"mon": {"start": 7, "stop": 20},"tue": {"start": 7, "stop": 20},"wed": {"start": 7, "stop": 20},"thu": {"start": 7, "stop": 20}, "fri": {"start": 7, "stop": 20}}

On a RDS instance the schedule tag is a string of keyword parameters separated by a space.

"mon_start=7 mon_stop=20 tue_start=7 tue_stop=20 wed_start=7 wed_stop=20 thu_start=7 thu_stop=20 fri_start=7 fri_stop=20"

NOTE: This is because of restrictions in the characters the tags on RDS instance support.

The scheduler can be configured to add a default schedule tag to EC2 and RDS instances it finds without a schedule tag. It ignores instances that are part of autoscaling groups assuming scheduling actions can be used to stop and start these instances.

Requirements

This module requires Terraform version 0.10.x or newer.

Dependencies

This module depends on a correctly configured AWS Provider in your Terraform codebase.

Usage

module "lambda-scheduler" {
  source = "neillturner/lambda-scheduler/aws"
  version = "0.2.0"
  schedule_expression = "cron(5 * * * ? *)"
  tag = "schedule"
  schedule_tag_force = "true"
  ec2_schedule = "true"
  rds_schedule = "true"
  default = "\{\"mon": {\"start\": 7, \"stop\": 20},\"tue\": {\"start\": 7, \"stop\": 20},\"wed\": {\"start\": 7, \"stop\": 20},\"thu\": {\"start\": 7, \"stop\": 20}, \"fri\": {\"start\": 7, \"stop\": 20}}"
  time = "local"
}

variables

schedule_expression

The aws cloudwatch event rule schedule expression that specifies when the scheduler runs.

Default = "cron(5 * * * ? *)" i.e. 5 minuts past the hour. for debugging use "rate(5 minutes)" See ScheduledEvents

tag

The tag name used on the EC2 and RDS instance to contain the schedule string for the instance. default is 'schedule'

schedule_tag_force

Whether to force the EC2 and RDS instance to have the default schedule tag if no schedule tag exists for the instance.

Default is false. If set to true it with create a default schedule tag for each instance it finds.

exclude

String containing comma separated list of ECS2 and RDS instance ids to exclude from scheduling.

default

The default schedule tag containing json schedule information to add to EC2 or RDS instance when schedule_tag_force set to true.

NOTE: On a RDS instance the tag is converted to a string of keyword parameters separated by a space. i.e.

"mon_start=7 mon_stop=20"

because of restrictions in the characters the tags on RDS instance support.

Default for default is:

{"mon": {"start": 7, "stop": 20},"tue": {"start": 7, "stop": 20},"wed": {"start": 7, "stop": 20},"thu": {"start": 7, "stop": 20}, "fri": {"start": 7, "stop": 20}}

time

Timezone to use for scheduler. Can be 'local' or 'gmt'. default is 'gmt'.

ec2_schedule

Whether to do scheduling for EC2 instances. default = "true".

rds_schedule

Whether to do scheduling for RDS instances. default = "true", }

Default is gmt. local time is for the AWS region.

security_group_ids

list of the vpc security groups to run lambda scheduler in. Defaults to []. Usually this does not need to be specified.

subnet_ids

list of subnet_ids that the scheduler runs in. Defaults to []. Usually this does not need to be specified.

terraform-aws-lambda-scheduler's People

Contributors

neillturner avatar

Watchers

NERDDISCO avatar James Cloos avatar Bert Scharpenberg avatar Bence Bodrogi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.