This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import logging | |
| import os | |
| import boto3 | |
| logger = logging.getLogger() | |
| logger.setLevel(logging.INFO) | |
| def turn_off_instance(instance_ids): | |
| ec2 = boto3.client('ec2', region_name=region) | |
| ec2.stop_instances(InstanceIds=instance_ids) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module "turn_off_ec2" { | |
| source = "../modules/..." | |
| instance_id = "i-0298c78d123dhjkld" | |
| evaluation_periods = "1" | |
| period = "600" | |
| metric_name = "ActiveSessions" | |
| namespace = "TableauServer" | |
| comparison_operator = "LessThanOrEqualToThreshold" | |
| threshold = "0" | |
| statistic = "Average" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import logging | |
| import os | |
| import boto3 | |
| logger = logging.getLogger() | |
| logger.setLevel(logging.INFO) | |
| def turn_off_instances(instance_ids): | |
| ec2 = boto3.client('ec2', region_name=region) | |
| ec2.stop_instances(InstanceIds=instance_ids) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| resource "aws_cloudwatch_event_rule" "schedule" { | |
| name = local.event_rule_name | |
| description = "enabling or disabling alarms at given intervals" | |
| schedule_expression = var.schedule | |
| } | |
| resource "aws_cloudwatch_event_target" "schedule_lambda" { | |
| rule = aws_cloudwatch_event_rule.on_schedule.name | |
| target_id = "processing_lambda" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data "archive_file" "lambda_zip" { | |
| type = "zip" | |
| source_file = "${path.module}/src/enable_disable_alarms_tf.py" | |
| output_file_mode = "0666" | |
| output_path = "${path.module}/bin/enable_disable_alarms_tf.zip" | |
| } | |
| resource "aws_lambda_function" "processing_lambda" { | |
| filename = data.archive_file.lambda_zip.output_path | |
| function_name = local.processing_lambda_name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import logging | |
| import os | |
| import boto3 | |
| logger = logging.getLogger() | |
| logger.setLevel(logging.INFO) | |
| def enable(alarm_names): | |
| try: | |
| enable_alarm = client.enable_alarm_actions(AlarmNames=alarm_names) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module "enable_or_disable_alarms" { | |
| source = "../modules/.." | |
| schedule = "cron(0/15 * ? * MON-FRI *)" | |
| alarm_arns_lst = ["arn:aws:cloudwatch:eu-east-1:123456757:alarm:testing-alarm"] | |
| action = "enable" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import logging | |
| import os | |
| import boto3 | |
| logger = logging.getLogger() | |
| logger.setLevel(logging.INFO) | |
| def disable_alarms(alarm_names): | |
| try: | |
| logger.info(f'Disabling alarms') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| resource "aws_cloudwatch_event_rule" "schedule" { | |
| name = "schedule" | |
| description = "Schedule for Lambda Function" | |
| schedule_expression = var.schedule | |
| } | |
| resource "aws_cloudwatch_event_target" "schedule_lambda" { | |
| rule = aws_cloudwatch_event_rule.schedule.name | |
| target_id = "processing_lambda" | |
| arn = aws_lambda_function.processing_lambda.arn |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data "archive_file" "lambda_zip" { | |
| type = "zip" | |
| source_file = "${path.module}/src/scheulde_test.py" | |
| output_file_mode = "0666" | |
| output_path = "${path.module}/bin/scheulde_test.py.zip" | |
| } | |
| resource "aws_lambda_function" "processing_lambda" { | |
| filename = data.archive_file.lambda_zip.output_path | |
| function_name = local.processing_lambda_name |