Forked from Kgirthofer/gist:60aa3952b91236fe5d77b798fd24ce42
Last active
March 13, 2019 15:56
-
-
Save christhomas/7cc76504e3ff093547fd295c3933380c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "stage_name" { | |
value = "default" | |
} | |
resource "aws_api_gateway_domain_name" "main" { | |
domain_name = "whatever.domain.com" | |
regional_certificate_arn = "arn:aws:acm:us-west-2:accountID:certificate/certID" | |
endpoint_configuration { | |
types = ["REGIONAL"] | |
} | |
} | |
resource "aws_route53_record" "api" { | |
provider = "aws.default" | |
zone_id = "${var.domain_zone_id}" | |
name = "whatever" | |
type = "A" | |
alias { | |
evaluate_target_health = true | |
name = "${aws_api_gateway_domain_name.main.regional_domain_name}" | |
zone_id = "${aws_api_gateway_domain_name.main.regional_zone_id}" | |
} | |
} | |
resource "aws_api_gateway_base_path_mapping" "main" { | |
api_id = "${aws_api_gateway_rest_api.main.id}" | |
stage_name = "" | |
domain_name = "${aws_api_gateway_domain_name.main.domain_name}" | |
} | |
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 = "" | |
} | |
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