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