Skip to content

Instantly share code, notes, and snippets.

@wshihadeh
wshihadeh / Marginalia.rb
Created April 22, 2020 06:28
Marginalia
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,
@wshihadeh
wshihadeh / MyJsonApiClient.rb
Created April 22, 2020 06:27
MyJsonApiClient
MyJsonApiClient.with_headers(RequestHeadersMiddleware.store) do
.. # Do the request by the MyJsonApiClient
end
@wshihadeh
wshihadeh / FARADAY.rb
Created April 22, 2020 06:26
FARADAY
FARADAY_SINGLETON = Faraday.new(
url: host,
headers: RequestHeadersMiddleware.store,
)
@wshihadeh
wshihadeh / resource.rb
Created April 22, 2020 06:25
BaseResource
class BaseResource < ActiveResource::Base
def self.headers
RequestHeadersMiddleware.store.merge(ActiveResource::Base.headers)
end
end
@wshihadeh
wshihadeh / aws_lambda_permission.tf
Created April 15, 2020 06:37
aws_lambda_permission
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"
}
@wshihadeh
wshihadeh / aws_cloudwatch_event_rule.tf
Created April 15, 2020 06:36
aws_cloudwatch_event_rule
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}"
}
@wshihadeh
wshihadeh / aws_lambda_function.tf
Created April 15, 2020 06:35
aws_lambda_function
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"
}
@wshihadeh
wshihadeh / iam.tf
Created April 15, 2020 06:35
aws_iam_role
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"
@wshihadeh
wshihadeh / config.tf
Created April 15, 2020 06:34
AWS policy
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",
@wshihadeh
wshihadeh / http_dep.json
Created April 13, 2020 07:42
Health check HTTP
{
"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": {