Skip to content
This repository was archived by the owner on Apr 3, 2022. It is now read-only.

Commit 90e8b17

Browse files
committed
Automated setup
1 parent 6e31a59 commit 90e8b17

File tree

4 files changed

+68
-67
lines changed

4 files changed

+68
-67
lines changed

terraform/apiGateway.tf

-22
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,6 @@ resource "aws_api_gateway_rest_api" "helloWorldGateway" {
1313

1414
}
1515

16-
resource "aws_api_gateway_resource" "helloWorld" {
17-
rest_api_id = "${aws_api_gateway_rest_api.helloWorldGateway.id}"
18-
parent_id = "${aws_api_gateway_rest_api.helloWorldGateway.root_resource_id}"
19-
path_part = "hello"
20-
}
21-
22-
resource "aws_api_gateway_method" "helloWorldGet" {
23-
rest_api_id = "${aws_api_gateway_rest_api.helloWorldGateway.id}"
24-
resource_id = "${aws_api_gateway_resource.helloWorld.id}"
25-
http_method = "GET"
26-
authorization = "NONE"
27-
}
28-
29-
resource "aws_api_gateway_integration" "helloWorldGet" {
30-
rest_api_id = "${aws_api_gateway_rest_api.helloWorldGateway.id}"
31-
resource_id = "${aws_api_gateway_resource.helloWorld.id}"
32-
http_method = "${aws_api_gateway_method.helloWorldGet.http_method}"
33-
integration_http_method = "POST"
34-
type = "AWS_PROXY"
35-
uri = "${aws_lambda_function.schibbler_helloWorldLambda.invoke_arn}"
36-
}
37-
3816
output "Gateway_URL" {
3917
value = "${aws_api_gateway_deployment.helloWorldGateway.invoke_url}"
4018
}

terraform/get_hello.tf

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
data "archive_file" "helloWorldLambdaZip" {
2+
type = "zip"
3+
source_dir = "functions/helloWorldLambda"
4+
output_path = "output/helloWorldLambda.zip"
5+
}
6+
7+
resource "aws_lambda_function" "schibbler_helloWorldLambda" {
8+
filename = "output/helloWorldLambda.zip"
9+
source_code_hash = "${data.archive_file.helloWorldLambdaZip.output_base64sha256}"
10+
function_name = "schibblerhelloWorldLambda"
11+
handler = "index.handler"
12+
role = "${aws_iam_role.helloWorldLambda.arn}"
13+
runtime = "nodejs8.10"
14+
}
15+
16+
data "aws_iam_policy_document" "helloWorldLambda_policy" {
17+
statement {
18+
actions = ["sts:AssumeRole"]
19+
principals {
20+
type = "Service"
21+
identifiers = ["lambda.amazonaws.com"]
22+
}
23+
effect = "Allow"
24+
}
25+
}
26+
27+
resource "aws_iam_role" "helloWorldLambda" {
28+
name = "schibbler_helloWorldLambda_role"
29+
30+
assume_role_policy = "${data.aws_iam_policy_document.helloWorldLambda_policy.json}"
31+
}
32+
33+
34+
resource "aws_iam_role_policy_attachment" "helloWorldLambda_policyAttachment" {
35+
role = "${aws_iam_role.helloWorldLambda.name}"
36+
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
37+
}
38+
39+
resource "aws_api_gateway_resource" "helloWorld" {
40+
rest_api_id = "${aws_api_gateway_rest_api.helloWorldGateway.id}"
41+
parent_id = "${aws_api_gateway_rest_api.helloWorldGateway.root_resource_id}"
42+
path_part = "hello"
43+
}
44+
45+
resource "aws_api_gateway_method" "helloWorldGet" {
46+
rest_api_id = "${aws_api_gateway_rest_api.helloWorldGateway.id}"
47+
resource_id = "${aws_api_gateway_resource.helloWorld.id}"
48+
http_method = "GET"
49+
authorization = "NONE"
50+
}
51+
52+
resource "aws_api_gateway_integration" "helloWorldGet" {
53+
rest_api_id = "${aws_api_gateway_rest_api.helloWorldGateway.id}"
54+
resource_id = "${aws_api_gateway_resource.helloWorld.id}"
55+
http_method = "${aws_api_gateway_method.helloWorldGet.http_method}"
56+
integration_http_method = "POST"
57+
type = "AWS_PROXY"
58+
uri = "${aws_lambda_function.schibbler_helloWorldLambda.invoke_arn}"
59+
}
60+
61+
resource "aws_lambda_permission" "restInvokation" {
62+
statement_id = "AllowExecutionFromAPIGateway"
63+
action = "lambda:InvokeFunction"
64+
function_name = "${aws_lambda_function.schibbler_helloWorldLambda.arn}"
65+
principal = "apigateway.amazonaws.com"
66+
67+
source_arn = "${aws_api_gateway_deployment.helloWorldGateway.execution_arn}/GET/hello"
68+
}

terraform/iam.tf

-22
This file was deleted.

terraform/lambda.tf

-23
This file was deleted.

0 commit comments

Comments
 (0)