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 Marginalia | |
module Comment | |
def self.request_id | |
RequestHeadersMiddleware.store[:'X-Request-Id'] if RequestHeadersMiddleware | |
end | |
end | |
end | |
Marginalia::Comment.components = [ | |
:application, | |
:controller_with_namespace, |
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
MyJsonApiClient.with_headers(RequestHeadersMiddleware.store) do | |
.. # Do the request by the MyJsonApiClient | |
end |
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
FARADAY_SINGLETON = Faraday.new( | |
url: host, | |
headers: RequestHeadersMiddleware.store, | |
) |
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
class BaseResource < ActiveResource::Base | |
def self.headers | |
RequestHeadersMiddleware.store.merge(ActiveResource::Base.headers) | |
end | |
end |
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_lambda_permission" "allow_cloudwatch_stop" { | |
statement_id = "AllowExecutionFromCloudWatch" | |
action = "lambda:InvokeFunction" | |
function_name = "${aws_lambda_function.stop_ec2_lambda.function_name}" | |
principal = "events.amazonaws.com" | |
} |
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" "ec2_stop_rule" { | |
name = "StopEC2Instances" | |
description = "Stop EC2 nodes at 19:00 from Monday to friday" | |
schedule_expression = "cron(0 19 ? * 2-6 *)" | |
} | |
resource "aws_cloudwatch_event_target" "ec2_stop_rule_target" { | |
rule = "${aws_cloudwatch_event_rule.ec2_stop_rule.name}" | |
arn = "${aws_lambda_function.stop_ec2_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
resource "aws_lambda_function" "stop_ec2_lambda" { | |
filename = "ec2_lambda_handler.zip" | |
function_name = "stopEC2Lambda" | |
role = "${aws_iam_role.stop_start_ec2_role.arn}" | |
handler = "ec2_lambda_handler.stop" | |
source_code_hash = "${filebase64sha256("ec2_lambda_handler.zip")}" | |
runtime = "python3.7" | |
memory_size = "250" | |
timeout = "60" | |
} |
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_iam_role" "stop_start_ec2_role" { | |
name = "StopStartEC2Role" | |
assume_role_policy = <<EOF | |
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Action": "sts:AssumeRole", | |
"Principal": { | |
"Service": "lambda.amazonaws.com" |
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_iam_policy" "stop_start_ec2_policy" { | |
name = "StopStartEC2Policy" | |
path = "/" | |
description = "IAM policy for stop and start EC2 from a lambda" | |
policy = <<EOF | |
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Effect": "Allow", |
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": { | |
"type": "checker", | |
"id": "1", | |
"attributes": { | |
"http://localhost:3090/health": { | |
"status": null, | |
"details": "Failed to open TCP connection to localhost:3090" | |
}, | |
"http://localhost:3000/health": { |