80ff6e804a
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
90 lines
2.2 KiB
HCL
90 lines
2.2 KiB
HCL
terraform {
|
|
required_version = ">=1.0"
|
|
|
|
required_providers {
|
|
aws = "4.32.0"
|
|
}
|
|
}
|
|
|
|
provider "aws" {
|
|
profile = "default"
|
|
region = var.aws_region
|
|
}
|
|
|
|
resource "aws_iam_role" "lambda_role" {
|
|
name = "lambda_role"
|
|
assume_role_policy = <<EOF
|
|
{
|
|
"Version": "2012-10-17",
|
|
"Statement": [
|
|
{
|
|
"Action": "sts:AssumeRole",
|
|
"Principal": {
|
|
"Service": "lambda.amazonaws.com"
|
|
},
|
|
"Effect": "Allow",
|
|
"Sid": ""
|
|
}
|
|
]
|
|
}
|
|
EOF
|
|
}
|
|
|
|
resource "aws_lambda_function" "lambda_func" {
|
|
function_name = "boilerplate_function"
|
|
role = aws_iam_role.lambda_role.arn
|
|
handler = "src.base.handler"
|
|
runtime = "python3.8"
|
|
|
|
s3_bucket = var.artifacts_bucket_name
|
|
s3_key = var.lambda_archive_name
|
|
}
|
|
|
|
resource "aws_api_gateway_rest_api" "gateway" {
|
|
name = "boilerplate"
|
|
description = "Lambda Boilerplate"
|
|
}
|
|
|
|
resource "aws_api_gateway_resource" "lambda_proxy" {
|
|
rest_api_id = aws_api_gateway_rest_api.gateway.id
|
|
parent_id = aws_api_gateway_rest_api.gateway.root_resource_id
|
|
path_part = "{proxy+}"
|
|
}
|
|
|
|
resource "aws_api_gateway_method" "lambda_proxy" {
|
|
rest_api_id = aws_api_gateway_rest_api.gateway.id
|
|
resource_id = aws_api_gateway_resource.lambda_proxy.id
|
|
http_method = "ANY"
|
|
authorization = "NONE"
|
|
}
|
|
|
|
resource "aws_api_gateway_integration" "lambda" {
|
|
rest_api_id = aws_api_gateway_rest_api.gateway.id
|
|
resource_id = aws_api_gateway_resource.lambda_proxy.id
|
|
http_method = aws_api_gateway_method.lambda_proxy.http_method
|
|
|
|
integration_http_method = "POST"
|
|
type = "AWS_PROXY"
|
|
uri = aws_lambda_function.lambda_func.invoke_arn
|
|
}
|
|
|
|
resource "aws_api_gateway_deployment" "lambda" {
|
|
depends_on = [
|
|
aws_api_gateway_integration.lambda
|
|
]
|
|
|
|
rest_api_id = aws_api_gateway_rest_api.gateway.id
|
|
stage_name = "test"
|
|
}
|
|
|
|
resource "aws_lambda_permission" "apigw" {
|
|
statement_id = "AllowAPIGatewayInvoke"
|
|
action = "lambda:InvokeFunction"
|
|
function_name = aws_lambda_function.lambda_func.function_name
|
|
principal = "apigateway.amazonaws.com"
|
|
source_arn = "${aws_api_gateway_rest_api.gateway.execution_arn}/*/*"
|
|
}
|
|
|
|
output "base_url" {
|
|
value = aws_api_gateway_deployment.lambda.invoke_url
|
|
}
|