Created
January 20, 2022 15:16
-
-
Save quatrix/54292fd0dcb15f166d4d1e4bfe1aa560 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
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" | |
parent_id = aws_api_gateway_rest_api.api.root_resource_id | |
rest_api_id = aws_api_gateway_rest_api.api.id | |
} | |
resource "aws_api_gateway_method" "lambda" { | |
rest_api_id = aws_api_gateway_rest_api.api.id | |
resource_id = aws_api_gateway_resource.lambda.id | |
http_method = "POST" | |
authorization = "CUSTOM" | |
authorizer_id = aws_api_gateway_authorizer.authorizer.id | |
} | |
resource "aws_api_gateway_integration" "redirect" { | |
rest_api_id = aws_api_gateway_rest_api.api.id | |
resource_id = aws_api_gateway_resource.lambda.id | |
http_method = aws_api_gateway_method.lambda.http_method | |
# Lambda invokes requires a POST method | |
integration_http_method = "POST" | |
type = "AWS_PROXY" | |
uri = aws_lambda_function.dead_man_switch.invoke_arn | |
} | |
resource "aws_api_gateway_deployment" "api" { | |
rest_api_id = aws_api_gateway_rest_api.api.id | |
triggers = { | |
redeployment = sha1(jsonencode(aws_api_gateway_rest_api.api.body)) | |
} | |
lifecycle { | |
create_before_destroy = true | |
} | |
} | |
resource "aws_api_gateway_stage" "gateway" { | |
deployment_id = aws_api_gateway_deployment.api.id | |
rest_api_id = aws_api_gateway_rest_api.api.id | |
stage_name = "prod" | |
} | |
resource "aws_api_gateway_authorizer" "authorizer" { | |
name = "authorizer" | |
rest_api_id = aws_api_gateway_rest_api.api.id | |
authorizer_uri = aws_lambda_function.authorizer.invoke_arn | |
authorizer_credentials = aws_iam_role.role.arn | |
} | |
resource "aws_api_gateway_base_path_mapping" "gateway" { | |
api_id = aws_api_gateway_rest_api.api.id | |
stage_name = aws_api_gateway_stage.gateway.stage_name | |
domain_name = aws_api_gateway_domain_name.i_am_alive.domain_name | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment