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
+ }
0 commit comments