<commit_before># Sourced from environment variables named TF_VAR_${VAR_NAME}
variable "aws_acct_id" {}
variable "jakesky_key" {}
variable "jakesky_latitude" {}
variable "jakesky_longitude" {}
variable "jakesky_skill_id" {}

variable "jakesky_filename" {
    type = "string"
    default = "JakeSky.zip"
}

variable "aws_region" {
    type = "string"
    default = "us-east-1"
}

provider "aws" {
    region = "${var.aws_region}"
}

resource "aws_cloudwatch_event_rule" "jakesky_schedule" {
    name = "jakesky-schedule"
    description = "Run jakesky periodically to keep the Lambda warmed"
    schedule_expression = "cron(0/5 11_13 ? * * *)"
}

data "aws_iam_policy_document" "jakesky_role_policy_document" {
    statement {
        actions = ["logs:CreateLogGroup"]
        resources = ["arn:aws:logs:${var.aws_region}:${var.aws_acct_id}:*"]
    }

    statement {
        actions = ["logs:CreateLogStream", "logs:PutLogEvents"]
        resources = ["arn:aws:logs:${var.aws_region}:${var.aws_acct_id}:log_group:/aws/lambda/jakesky:*"]
    }
}

data "aws_iam_policy_document" "jakesky_assume_role_policy_document" {
    statement {
        principals {
            type = "Service"
            identifiers = ["lambda.amazonaws.com"]
        }
        actions = ["sts:AssumeRole"]
    }
}

resource "aws_iam_policy" "jakesky_role_policy" {
    name = "jakesky"
    policy = "${data.aws_iam_policy_document.jakesky_role_policy_document.json}"
}

resource "aws_iam_role" "jakesky_role" {
    name = "jakesky"
    assume_role_policy = "${data.aws_iam_policy_document.jakesky_assume_role_policy_document.json}"
}

resource "aws_iam_role_policy_attachment" "jakesky_role_attachment" {
    role       = "${aws_iam_role.jakesky_role.name}"
    policy_arn = "${aws_iam_policy.jakesky_role_policy.arn}"
}

resource "aws_lambda_function" "jakesky" {
    filename = "${var.jakesky_filename}"
    function_name = "jakesky"
    role = "${aws_iam_role.jakesky_role.arn}"
    handler = "jakesky.alexa_handler"
    source_code_hash = "${base64sha256(file("${var.jakesky_filename}"))}"
    runtime = "python2.7"
    publish = "false"
    description = "Retrieve local weather from DarkSky for commutes and lunchtime"

    environment {
        variables = {
            JAKESKY_KEY = "${var.jakesky_key}"
            JAKESKY_LATITUDE = "${var.jakesky_latitude}"
            JAKESKY_LONGITUDE = "${var.jakesky_longitude}"
            JAKESKY_SKILL_ID = "${var.jakesky_skill_id}"
        }
    }
}

resource "aws_cloudwatch_log_group" "jakesky_logs" {<commit_msg>Add default lambda KMS key to Jakesky function<commit_after># Sourced from environment variables named TF_VAR_${VAR_NAME}
variable "aws_acct_id" {}
variable "jakesky_key" {}
variable "jakesky_latitude" {}
variable "jakesky_longitude" {}
variable "jakesky_skill_id" {}

variable "jakesky_filename" {
    type = "string"
    default = "JakeSky.zip"
}

variable "aws_region" {
    type = "string"
    default = "us-east-1"
}

provider "aws" {
    region = "${var.aws_region}"
}

resource "aws_cloudwatch_event_rule" "jakesky_schedule" {
    name = "jakesky-schedule"
    description = "Run jakesky periodically to keep the Lambda warmed"
    schedule_expression = "cron(0/5 11_13 ? * * *)"
}

resource "aws_kms_key" "lambda_default_key" {
    enable_key_rotation = "true"
}

data "aws_iam_policy_document" "jakesky_role_policy_document" {
    statement {
        actions = ["logs:CreateLogGroup"]
        resources = ["arn:aws:logs:${var.aws_region}:${var.aws_acct_id}:*"]
    }

    statement {
        actions = ["logs:CreateLogStream", "logs:PutLogEvents"]
        resources = ["arn:aws:logs:${var.aws_region}:${var.aws_acct_id}:log_group:/aws/lambda/jakesky:*"]
    }
}

data "aws_iam_policy_document" "jakesky_assume_role_policy_document" {
    statement {
        principals {
            type = "Service"
            identifiers = ["lambda.amazonaws.com"]
        }
        actions = ["sts:AssumeRole"]
    }
}

resource "aws_iam_policy" "jakesky_role_policy" {
    name = "jakesky"
    policy = "${data.aws_iam_policy_document.jakesky_role_policy_document.json}"
}

resource "aws_iam_role" "jakesky_role" {
    name = "jakesky"
    assume_role_policy = "${data.aws_iam_policy_document.jakesky_assume_role_policy_document.json}"
}

resource "aws_iam_role_policy_attachment" "jakesky_role_attachment" {
    role       = "${aws_iam_role.jakesky_role.name}"
    policy_arn = "${aws_iam_policy.jakesky_role_policy.arn}"
}

resource "aws_lambda_function" "jakesky" {
    filename = "${var.jakesky_filename}"
    function_name = "jakesky"
    role = "${aws_iam_role.jakesky_role.arn}"
    handler = "jakesky.alexa_handler"
    source_code_hash = "${base64sha256(file("${var.jakesky_filename}"))}"
    runtime = "python2.7"
    publish = "false"
    description = "Retrieve local weather from DarkSky for commutes and lunchtime"

    kms_key_arn = "${aws_kms_key.lambda_default_key.arn}"
    environment {
        variables = {
            JAKESKY_KEY = "${var.jakesky_key}"
            JAKESKY_LATITUDE = "${var.jakesky_latitude}"
            JAKESKY_LONGITUDE = "${var.jakesky_longitude}"
            JAKESKY_SKILL_ID = "${var.jakesky_skill_id}"
        }
    }
}

resource "aws_cloudwatch_log_group" "jakesky_logs" {
{'fraction_non_alphanumeric': 0.12835139760410724, 'fraction_numerical': 0.0053242061228370415, 'mean_word_length': 3.8345588235294117, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1614014', 'n_tokens_mistral': 1896, 'n_tokens_neox': 1865, 'n_words': 286}