-
Notifications
You must be signed in to change notification settings - Fork 1
/
api-docs.tf
60 lines (49 loc) · 1.89 KB
/
api-docs.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
resource "aws_lambda_function" "api_docs_handler" {
function_name = "api-docs-handler"
role = aws_iam_role.api_docs_handler.arn
filename = data.archive_file.api_docs_handler.output_path
source_code_hash = data.archive_file.api_docs_handler.output_base64sha256
handler = "main.lambda_handler"
layers = [aws_lambda_layer_version.api_docs_requirements.arn]
runtime = "python3.11"
}
data "archive_file" "api_docs_handler" {
type = "zip"
source_dir = "${path.module}/src/api-docs"
output_path = "${path.module}/dist/api-docs-lambda.zip"
}
resource "aws_lambda_layer_version" "api_docs_requirements" {
layer_name = "api-docs-requirements"
filename = "${path.module}/dist/api-docs-requirements.zip"
source_code_hash = filebase64sha256("${path.module}/dist/api-docs-requirements.zip")
compatible_runtimes = ["python3.11"]
}
resource "aws_iam_role" "api_docs_handler" {
name = "api-docs-handler"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = "lambda.amazonaws.com"
}
},
]
})
}
resource "aws_iam_role_policy_attachment" "api_docs_handler_cloudwatch_access" {
role = aws_iam_role.api_docs_handler.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}
resource "aws_iam_role_policy_attachment" "api_docs_handler_api_gateway_access" {
role = aws_iam_role.api_docs_handler.name
policy_arn = "arn:aws:iam::aws:policy/AmazonAPIGatewayAdministrator"
}
resource "aws_lambda_permission" "api_docs_handler" {
function_name = aws_lambda_function.api_docs_handler.function_name
action = "lambda:InvokeFunction"
principal = "apigateway.amazonaws.com"
source_arn = "${aws_api_gateway_rest_api.this.execution_arn}/*"
}