-
Notifications
You must be signed in to change notification settings - Fork 0
/
lambda.tf
62 lines (54 loc) · 1.5 KB
/
lambda.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
61
62
# Create AWS Lambda Function from ECR Image
resource "aws_lambda_function" "nginx" {
depends_on = [
aws_ecr_repository.ecr,
null_resource.build,
aws_iam_role.lambda
]
function_name = var.project_name
architectures = [
"arm64"
]
package_type = "Image"
image_uri = "${aws_ecr_repository.ecr.repository_url}:latest"
role = aws_iam_role.lambda.arn
memory_size = 1024
environment {
variables = {
RUST_LOG = "debug"
PORT = "8080"
}
}
}
# Update Lambda Image to latest with Lambda API
resource "null_resource" "post_deployment" {
depends_on = [
aws_lambda_function.nginx,
null_resource.build
]
triggers = {
build_number = timestamp()
}
provisioner "local-exec" {
interpreter = [
"/bin/sh",
"-c"
]
command = <<-COMMAND
# Update Lambda Image to latest with Lambda API
aws lambda update-function-code --function-name ${aws_lambda_function.nginx.function_name} --region ap-southeast-1 --image-uri ${aws_ecr_repository.ecr.repository_url}:latest
COMMAND
}
}
# Add API GW Lambda Permission
resource "aws_lambda_permission" "api_gateway" {
depends_on = [
aws_lambda_function.nginx,
aws_api_gateway_deployment.api
]
statement_id = "AllowExecutionFromAPIGateway"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.nginx.function_name
principal = "apigateway.amazonaws.com"
source_arn = "${aws_api_gateway_rest_api.api.execution_arn}/*/*/*"
}