Skip to content

Generalize the code to run any lambda #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,18 @@ data "aws_caller_identity" "current" {}

#Create up our Lambda function to proxy requests to our VPC
resource "aws_lambda_function" "lambda" {
filename = "${path.module}/proxy_api.zip"
function_name = "proxy_api_${var.name}"
filename = "${path.module}/${var.lambda_name}.zip"
function_name = "${var.lambda_name}_${var.name}"
role = "${aws_iam_role.lambda_role.arn}"
handler = "index.myHandler"
runtime = "nodejs6.10"
source_code_hash = "${base64sha256(file("${path.module}/proxy_api.zip"))}"
handler = "${var.lambda_hander}"
runtime = "${var.lambda_engine}"
source_code_hash = "${base64sha256(file("${path.module}/${var.lambda_name}.zip"))}"
timeout = "10"
vpc_config = {
subnet_ids = ["${var.subnet_ids}"]
security_group_ids = ["${var.security_group_ids}"]
}
environment {
variables = {
PROXY_HOST = "${var.proxy_hostname}"
PROXY_PORT = "${var.proxy_port}"
}
}
environment = "${var.lambda_env}"
}

#The role assigned to the lambda function.
Expand Down Expand Up @@ -90,7 +85,7 @@ resource "aws_iam_policy_attachment" "lambda_vpc" {
#Initialize the REST API
resource "aws_api_gateway_rest_api" "api_gw" {
name = "${var.name}_proxy_api"
description = "API Gateway to talk to microservices"
description = "API Gateway to talk to run ${var.lambda_name}"
}

#Set up proxy resource path
Expand Down
34 changes: 25 additions & 9 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@ variable "region" {
description = "Region must be specified"
}

variable "proxy_hostname" {
description = "Hostname for Fabio"
}

variable "proxy_port" {
description = "Port for Nomad API"
default = "80"
}

variable "subnet_ids" {
type = "list"
description = "Subnet IDs to associate with Lambda Function"
Expand All @@ -34,3 +25,28 @@ variable "burst_limit" {
variable "rate_limit" {
default = 10
}

variable "lambda_name" {
description = "lambda name to load"
default = "proxy.zip"
}

variable "lambda_handler" {
description = "lambda handler function name"
default = "index.myHandler"
}

variable "lambda_engine" {
description = "engine to run the lambda code"
default = "nodejs6.10"
}

variable "lambda_env" {
description = "A mapping of environment variables to pass for lambda"
default = {
variables = {
PROXY_HOST = "test"
PROXY_PORT = "80"
}
}
}