Created
January 20, 2022 15:26
-
-
Save quatrix/ced039c9b7135665877c60da62bb5a07 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data "aws_caller_identity" "current" {} | |
data "aws_region" "current" {} | |
resource "aws_iam_role" "role" { | |
name = "iam_for_lambda" | |
assume_role_policy = <<EOF | |
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Action": "sts:AssumeRole", | |
"Principal": { | |
"Service": ["apigateway.amazonaws.com", "lambda.amazonaws.com"] | |
}, | |
"Effect": "Allow", | |
"Sid": "" | |
} | |
] | |
} | |
EOF | |
} | |
resource "aws_iam_role_policy" "invocation_policy" { | |
name = "authorizer" | |
role = aws_iam_role.role.id | |
policy = <<EOF | |
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Action": "lambda:InvokeFunction", | |
"Effect": "Allow", | |
"Resource": "${aws_lambda_function.authorizer.arn}" | |
}, | |
{ | |
"Effect": "Allow", | |
"Action": [ | |
"logs:CreateLogStream", | |
"logs:PutLogEvents", | |
"logs:CreateLogGroup" | |
], | |
"Resource": [ | |
"arn:aws:logs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:log-group:/aws/lambda/*" | |
] | |
} | |
] | |
} | |
EOF | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment