-
Notifications
You must be signed in to change notification settings - Fork 0
/
iam_lambda_role.tf
57 lines (51 loc) · 1.74 KB
/
iam_lambda_role.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
54
55
56
57
locals {
lambda_role_policy = templatefile("template_files/lambda_policy.json.tpl",
{
default_lambda_arn = aws_lambda_function.default_route.arn
connect_lambda_arn = aws_lambda_function.connect_route.arn
disconnect_lambda_arn = aws_lambda_function.disconnect_route.arn
random_word_lambda_arn = aws_lambda_function.random_word_route.arn
wss_api_arn = aws_apigatewayv2_api.websocket_api.arn
}
)
}
### IAM role for Lambda
resource "aws_iam_role" "wss_lambda_role" {
name = "wss_lambda_role"
assume_role_policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
POLICY
}
### IAM policy for allowing the WebSocket API to invoke Lambda functions
resource "aws_iam_policy" "api_gtw_lambda_access" {
name = "AllowExecutionFromAPIGateway"
description = "IAM policy for allow API Gateway to execute getRandomWord Lambda function."
policy = local.lambda_role_policy
}
### IAM policy attachment
resource "aws_iam_role_policy_attachment" "api_gtw_lambda_access_attachment" {
role = aws_iam_role.wss_lambda_role.name
policy_arn = aws_iam_policy.api_gtw_lambda_access.arn
}
### IAM LambdaExecute policy attachment
resource "aws_iam_role_policy_attachment" "api_gtw_lambda_execute_attachment" {
role = aws_iam_role.wss_lambda_role.name
policy_arn = "arn:aws:iam::aws:policy/AWSLambdaExecute"
}
### IAM DynamoDB policy attachment
resource "aws_iam_role_policy_attachment" "api_gtw_dynamo_db_attachment" {
role = aws_iam_role.wss_lambda_role.name
policy_arn = "arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess"
}