-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tf
More file actions
65 lines (57 loc) · 1.55 KB
/
main.tf
File metadata and controls
65 lines (57 loc) · 1.55 KB
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
61
62
63
64
65
provider "aws" {
region = "eu-west-3"
}
variable "redis_password" {
type = string
description = "Redis password from OS environment"
sensitive = true
}
resource "aws_iam_role" "lambda_exec" {
name = "crypto-api-lambda-role"
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" "lambda_basic_execution" {
role = aws_iam_role.lambda_exec.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}
resource "aws_lambda_function" "crypto_api" {
function_name = "crypto-api"
role = aws_iam_role.lambda_exec.arn
handler = "lambda.handler"
runtime = "nodejs24.x"
filename = "lambda.zip"
source_code_hash = filebase64sha256("lambda.zip")
timeout = 30
memory_size = 256
environment {
variables = {
REDIS_PARIS_PASSWORD = var.redis_password
TEMP_DIR = "/tmp"
}
}
}
resource "aws_lambda_function_url" "api" {
function_name = aws_lambda_function.crypto_api.function_name
authorization_type = "NONE"
cors {
allow_origins = ["https://socketsguru.github.io"]
allow_methods = ["*"]
allow_headers = ["*"]
expose_headers = ["x-recovery-key", "content-disposition"]
max_age = 86400
}
}
output "api_url" {
value = aws_lambda_function_url.api.function_url
}