-
Notifications
You must be signed in to change notification settings - Fork 0
/
getStore.tf
54 lines (40 loc) · 1.51 KB
/
getStore.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
# ############ LAMBDA ############
resource "aws_lambda_function" "getStore" {
function_name = "${terraform.workspace}GetStore"
s3_bucket = aws_s3_bucket.lambda_bucket.id
s3_key = aws_s3_object.lambda_hello_world.key
runtime = "nodejs14.x"
handler = "store.getStore"
source_code_hash = data.archive_file.lambda_hello_world.output_base64sha256
role = aws_iam_role.lambda_exec.arn
environment {
variables = {
STORES_TABLE = "${terraform.workspace}Stores"
}
}
}
resource "aws_lambda_permission" "api_gw_get_store" {
statement_id = "AllowExecutionFromAPIGateway"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.getStore.function_name
principal = "apigateway.amazonaws.com"
source_arn = "${aws_apigatewayv2_api.lambda.execution_arn}/*/*"
}
resource "aws_cloudwatch_log_group" "getStore" {
name = "/aws/lambda/${aws_lambda_function.getStore.function_name}"
retention_in_days = 30
}
# ############ API GATEWAY ############
resource "aws_apigatewayv2_integration" "getStore" {
api_id = aws_apigatewayv2_api.lambda.id
integration_type = "AWS_PROXY"
integration_method = "POST"
integration_uri = aws_lambda_function.getStore.invoke_arn
}
resource "aws_apigatewayv2_route" "getStore" {
api_id = aws_apigatewayv2_api.lambda.id
route_key = "GET /stores"
target = "integrations/${aws_apigatewayv2_integration.getStore.id}"
authorizer_id = aws_apigatewayv2_authorizer.customAuthorizer.id
authorization_type = "CUSTOM"
}