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

Commit 6e31a59

Browse files
committed
Automated setup
1 parent 5ab8830 commit 6e31a59

File tree

7 files changed

+79
-25
lines changed

7 files changed

+79
-25
lines changed

.travis.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ jobs:
2626
- stage: delete
2727
name: Delete all created resources
2828
script:
29-
- "./bin/terraform destroy -auto-approve terraform"
29+
# - "./bin/terraform destroy -auto-approve terraform"
30+
- echo "Will currently not delete anything."

README.md

-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,4 @@ Die Lambda Funktionen werden automatisch verpackt und bei Änderungen hochgelade
3535

3636
### Lambda
3737

38-
### DynamoDb
39-
4038
### API Gateway

functions/helloWorldLambda/index.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const handler = (event, _, callback) => {
2+
var response = {
3+
statusCode: 200,
4+
headers: {
5+
'Content-Type': 'text/html; charset=utf-8',
6+
},
7+
body: "<p>Hello world!</p>",
8+
};
9+
callback(null, response);
10+
}
11+
12+
module.exports = {
13+
handler
14+
}

functions/loginLambda/index.js

-8
This file was deleted.

terraform/apiGateway.tf

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
resource "aws_api_gateway_deployment" "helloWorldGateway" {
2+
depends_on = [
3+
"aws_api_gateway_integration.helloWorldGet"
4+
]
5+
6+
rest_api_id = "${aws_api_gateway_rest_api.helloWorldGateway.id}"
7+
stage_name = "beta"
8+
}
9+
10+
resource "aws_api_gateway_rest_api" "helloWorldGateway" {
11+
name = "helloWorldApiGateway"
12+
description = "Hello world example"
13+
14+
}
15+
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+
38+
output "Gateway_URL" {
39+
value = "${aws_api_gateway_deployment.helloWorldGateway.invoke_url}"
40+
}

terraform/iam.tf

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
data "aws_iam_policy_document" "loginLambda_policy" {
1+
data "aws_iam_policy_document" "helloWorldLambda_policy" {
22
statement {
33
actions = ["sts:AssumeRole"]
44
principals {
@@ -9,14 +9,14 @@ data "aws_iam_policy_document" "loginLambda_policy" {
99
}
1010
}
1111

12-
resource "aws_iam_role" "loginLambda" {
13-
name = "schibbler_loginLambda_iam"
12+
resource "aws_iam_role" "helloWorldLambda" {
13+
name = "schibbler_helloWorldLambda_role"
1414

15-
assume_role_policy = "${data.aws_iam_policy_document.loginLambda_policy.json}"
15+
assume_role_policy = "${data.aws_iam_policy_document.helloWorldLambda_policy.json}"
1616
}
1717

1818

19-
resource "aws_iam_role_policy_attachment" "loginLambda_policyAttachment" {
20-
role = "${aws_iam_role.loginLambda.name}"
19+
resource "aws_iam_role_policy_attachment" "helloWorldLambda_policyAttachment" {
20+
role = "${aws_iam_role.helloWorldLambda.name}"
2121
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
2222
}

terraform/lambda.tf

+17-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1-
data "archive_file" "loginLambdaZip" {
1+
data "archive_file" "helloWorldLambdaZip" {
22
type = "zip"
3-
source_dir = "functions/loginLambda"
4-
output_path = "output/loginLambda.zip"
3+
source_dir = "functions/helloWorldLambda"
4+
output_path = "output/helloWorldLambda.zip"
55
}
66

7-
resource "aws_lambda_function" "schibbler_loginLambda" {
8-
filename = "output/loginLambda.zip"
9-
source_code_hash = "${data.archive_file.loginLambdaZip.output_base64sha256}"
10-
function_name = "schibblerLoginLambda"
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"
1111
handler = "index.handler"
12-
role = "${aws_iam_role.loginLambda.arn}"
12+
role = "${aws_iam_role.helloWorldLambda.arn}"
1313
runtime = "nodejs8.10"
14+
}
15+
16+
resource "aws_lambda_permission" "restInvokation" {
17+
statement_id = "AllowExecutionFromAPIGateway"
18+
action = "lambda:InvokeFunction"
19+
function_name = "${aws_lambda_function.schibbler_helloWorldLambda.arn}"
20+
principal = "apigateway.amazonaws.com"
21+
22+
source_arn = "${aws_api_gateway_deployment.helloWorldGateway.execution_arn}/GET/hello"
1423
}

0 commit comments

Comments
 (0)