Skip to content

Instantly share code, notes, and snippets.

resource "aws_cloudwatch_metric_alarm" "alarm" {
alarm_name = "dead_man_switch"
comparison_operator = "LessThanOrEqualToThreshold"
evaluation_periods = "1"
statistic = "Average"
metric_name = "Invocations"
namespace = "AWS/Lambda"
period = "60"
threshold = "0"
treat_missing_data = "breaching"
data "aws_caller_identity" "current" {}
data "aws_region" "current" {}
resource "aws_iam_role" "role" {
name = "iam_for_lambda"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
@quatrix
quatrix / dns.tf
Last active January 20, 2022 15:22
data "aws_acm_certificate" "cert" {
domain = "*.your-domain.com"
statuses = ["ISSUED"]
types = ["AMAZON_ISSUED"]
most_recent = true
}
data "aws_route53_zone" "zone" {
name = "your-domain.com"
private_zone = false
resource "aws_api_gateway_rest_api" "api" {
name = "dead_man_switch"
endpoint_configuration {
types = ["REGIONAL"]
}
}
resource "aws_api_gateway_resource" "lambda" {
path_part = "i_am_alive"
exports.handler = function(event, context, callback) {
var token = event.authorizationToken;
if (token == 'Basic XXXXXXXXXXXXXX') {
return callback(null, generatePolicy('user', 'Allow', event.methodArn));
}
else {
return callback(null, generatePolicy('user', 'Deny', event.methodArn));
}
};
module.exports.handler = async (event) => {
let responseMessage = 'Hello, World!';
return {
statusCode: 200,
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
message: responseMessage,
data "archive_file" "dead_man_switch" {
type = "zip"
output_path = "${path.module}/files/dead_man_switch.zip"
source_file = "lambdas/dead_man_switch.js"
}
data "archive_file" "authorizer" {
type = "zip"
output_path = "${path.module}/files/authorizer.zip"
source_file = "lambdas/authorizer.js"
resource "aws_sns_topic" "pagerduty_service" {
name = "pagerduty_service"
}
resource "aws_sns_topic_subscription" "pagerduty_service" {
topic_arn = aws_sns_topic.pagerduty_service.arn
protocol = "https"
endpoint = "https://events.pagerduty.com/integration/{your-integration-key}/enqueue"
}
/*
Test for successful dynamic linkage with Tensorflow, either as an API, or as a 'main' exec
*/
#include <vector>
#include <tensorflow/core/public/session.h>
const toChunks = (input: string, chunkSize) => {
const i = Math.ceil(Math.random() * Math.min(chunkSize, input.length))
if (!input.length) {
return []
}
const head = input.slice(0, i)
const tail = input.slice(i, input.length)