-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnewstructure.txt
More file actions
82 lines (73 loc) · 2.55 KB
/
newstructure.txt
File metadata and controls
82 lines (73 loc) · 2.55 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
serverless-hello-world/
├── apps/a
│ ├── lambda/
│ │ ├── index.js
│ │ ├── package.json
├── infrastructure/
│ ├── terraform/
│ │ ├── main.tf
│ │ ├── modules/
│ │ │ ├── lambda/
│ │ │ │ ├── main.tf
│ │ │ │ ├── variables.tf
│ │ │ │ ├── outputs.tf
│ │ │ ├── api_gateway/
│ │ │ │ ├── main.tf
│ │ │ │ ├── variables.tf
│ │ │ │ ├── outputs.tf
│ │ │ ├── cognito/
│ │ │ │ ├── main.tf
│ │ │ │ ├── variables.tf
│ │ │ │ ├── outputs.tf
│ │ ├── variables.tf
│ │ ├── outputs.tf
│ │ ├── provider.tf
├── .github/
│ ├── workflows/
│ │ ├── deploy.yml
├── README.md
```
#### **modules/api_gateway/main.tf**
```hcl
resource "aws_api_gateway_rest_api" "api" {
name = "hello-world-api"
description = "API Gateway for Hello World Lambda"
}
resource "aws_api_gateway_resource" "proxy" {
rest_api_id = aws_api_gateway_rest_api.api.id
parent_id = aws_api_gateway_rest_api.api.root_resource_id
path_part = "hello"
}
resource "aws_api_gateway_method" "proxy_method" {
rest_api_id = aws_api_gateway_rest_api.api.id
resource_id = aws_api_gateway_resource.proxy.id
http_method = "GET"
authorization = "COGNITO_USER_POOLS"
authorizer_id = aws_api_gateway_authorizer.cognito.id
}
resource "aws_api_gateway_integration" "lambda" {
rest_api_id = aws_api_gateway_rest_api.api.id
resource_id = aws_api_gateway_resource.proxy.id
http_method = aws_api_gateway_method.proxy_method.http_method
integration_http_method = "POST"
type = "AWS_PROXY"
uri = aws_lambda_function.hello_lambda.invoke_arn
}
resource "aws_api_gateway_authorizer" "cognito" {
name = "cognito-authorizer"
rest_api_id = aws_api_gateway_rest_api.api.id
type = "COGNITO_USER_POOLS"
provider_arns = [aws_cognito_user_pool.user_pool.arn]
}
```
#### **modules/cognito/main.tf**
```hcl
resource "aws_cognito_user_pool" "user_pool" {
name = "hello-world-user-pool"
}
resource "aws_cognito_user_pool_client" "user_pool_client" {
name = "hello-world-client"
user_pool_id = aws_cognito_user_pool.user_pool.id
generate_secret = false
explicit_auth_flows = ["ALLOW_USER_PASSWORD_AUTH", "ALLOW_REFRESH_TOKEN_AUTH"]
}