-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateStore.tf
53 lines (38 loc) · 1.43 KB
/
createStore.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" "createStore" {
function_name = "${terraform.workspace}CreateStore"
s3_bucket = aws_s3_bucket.lambda_bucket.id
s3_key = aws_s3_object.lambda_hello_world.key
runtime = "nodejs14.x"
handler = "store.createStore"
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_create_store" {
statement_id = "AllowExecutionFromAPIGateway"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.createStore.function_name
principal = "apigateway.amazonaws.com"
source_arn = "${aws_apigatewayv2_api.lambda.execution_arn}/*/*"
}
resource "aws_cloudwatch_log_group" "createStore" {
name = "/aws/lambda/${aws_lambda_function.createStore.function_name}"
retention_in_days = 30
}
# ############ API GATEWAY ############
resource "aws_apigatewayv2_integration" "createStore" {
api_id = aws_apigatewayv2_api.lambda.id
integration_type = "AWS_PROXY"
integration_method = "POST"
integration_uri = aws_lambda_function.createStore.invoke_arn
}
resource "aws_apigatewayv2_route" "createStore" {
api_id = aws_apigatewayv2_api.lambda.id
route_key = "POST /stores"
target = "integrations/${aws_apigatewayv2_integration.createStore.id}"
}