Skip to content

Instantly share code, notes, and snippets.

@Kgirthofer
Created March 13, 2019 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Kgirthofer/60aa3952b91236fe5d77b798fd24ce42 to your computer and use it in GitHub Desktop.
Save Kgirthofer/60aa3952b91236fe5d77b798fd24ce42 to your computer and use it in GitHub Desktop.
resource "aws_lambda_function" "main" {
function_name = "${var.function_name}"
s3_bucket = "${var.deployment_bucket}"
s3_key = "${var.bundle_key}"
handler = "${var.handler}"
runtime = "${var.runtime}"
timeout = "60"
memory_size = "256"
role = "${aws_iam_role.lambda_exec.arn}"
tags {
"Managed By" = "Terraform"
"App" = "${var.function_name}"
}
}
resource "aws_lambda_permission" "apigwPermissions" {
statement_id = "AllowAPIGatewayInvoke"
action = "lambda:InvokeFunction"
function_name = "${aws_lambda_function.main.arn}"
principal = "apigateway.amazonaws.com"
source_arn = "${aws_api_gateway_deployment.main.execution_arn}/*/*"
}
resource "aws_api_gateway_resource" "main" {
rest_api_id = "${var.core_gateway_id}"
parent_id = "${var.core_gateway_resource_id}"
path_part = "${var.path_part}"
}
resource "aws_api_gateway_method" "main" {
rest_api_id = "${var.core_gateway_id}"
resource_id = "${aws_api_gateway_resource.main.id}"
http_method = "${var.http_method}"
authorization = "NONE"
}
resource "aws_api_gateway_integration" "mainLambda" {
rest_api_id = "${var.core_gateway_id}"
resource_id = "${aws_api_gateway_method.main.resource_id}"
http_method = "${aws_api_gateway_method.main.http_method}"
integration_http_method = "${var.http_method}"
type = "AWS_PROXY"
uri = "${aws_lambda_function.main.invoke_arn}"
}
resource "aws_api_gateway_deployment" "main" {
depends_on = [
"aws_api_gateway_integration.mainLambda",
]
rest_api_id = "${var.core_gateway_id}"
stage_name = "${var.stage_name}"
}
resource "aws_api_gateway_rest_api" "api" {
name = "${var.env}_api_gateway"
description = "Terraform Serverless Application Example"
endpoint_configuration {
types = ["REGIONAL"]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment