-
Notifications
You must be signed in to change notification settings - Fork 1
/
lambda.tf
47 lines (41 loc) · 1.25 KB
/
lambda.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
resource "aws_lambda_function" "ha_alexa" {
function_name = "home-assistant-alexa"
filename = "./lambda_function.zip"
source_code_hash = filebase64sha256("./lambda_function.zip")
handler = "lambda_function.lambda_handler"
runtime = "python3.8"
role = aws_iam_role.lambda_iam_role.arn
environment {
variables = {
"DEBUG" = var.debug
"BASE_URL" = var.ha_url
}
}
}
resource "aws_iam_role" "lambda_iam_role" {
name = "haaska-lambda-role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action : "sts:AssumeRole",
Principal : {
Service : "lambda.amazonaws.com"
},
Effect : "Allow",
Sid : ""
},
]
})
}
resource "aws_iam_role_policy_attachment" "lambda_attachment" {
role = aws_iam_role.lambda_iam_role.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}
resource "aws_lambda_permission" "alexa" {
statement_id = "AllowExecutionFromAlexa"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.ha_alexa.function_name
principal = "alexa-connectedhome.amazon.com"
event_source_token = var.alexa_skill_id
}