Difference between revisions of "Terraform resource: aws lambda function"
Jump to navigation
Jump to search
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | <code>[[aws_lambda_function]]</code> | + | <code>[[aws_lambda_function]]</code> https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_function |
− | |||
== Official example == | == Official example == | ||
Line 7: | Line 6: | ||
statement { | statement { | ||
effect = "Allow" | effect = "Allow" | ||
− | + | ||
principals { | principals { | ||
type = "Service" | type = "Service" | ||
identifiers = ["lambda.amazonaws.com"] | identifiers = ["lambda.amazonaws.com"] | ||
} | } | ||
− | + | ||
actions = ["sts:AssumeRole"] | actions = ["sts:AssumeRole"] | ||
} | } | ||
} | } | ||
− | resource "aws_iam_role" "iam_for_lambda" { | + | resource "aws_iam_role" "iam_for_lambda" { |
name = "iam_for_lambda" | name = "iam_for_lambda" | ||
assume_role_policy = data.aws_iam_policy_document.assume_role.json | assume_role_policy = data.aws_iam_policy_document.assume_role.json | ||
− | } | + | } |
− | data "archive_file" "lambda" { | + | data "[[archive_file]]" "lambda" { |
type = "zip" | type = "zip" | ||
source_file = "lambda.js" | source_file = "lambda.js" | ||
output_path = "lambda_function_payload.zip" | output_path = "lambda_function_payload.zip" | ||
− | } | + | } |
− | resource "aws_lambda_function" "test_lambda" { | + | resource "aws_lambda_function" "test_lambda" { |
# If the file is not in the current working directory you will need to include a | # If the file is not in the current working directory you will need to include a | ||
# path.module in the filename. | # path.module in the filename. | ||
Line 35: | Line 34: | ||
role = aws_iam_role.iam_for_lambda.arn | role = aws_iam_role.iam_for_lambda.arn | ||
handler = "index.test" | handler = "index.test" | ||
− | + | ||
source_code_hash = data.archive_file.lambda.output_base64sha256 | source_code_hash = data.archive_file.lambda.output_base64sha256 | ||
Latest revision as of 12:50, 9 October 2024
aws_lambda_function
https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_function
Official example[edit]
data "aws_iam_policy_document" "assume_role" { statement { effect = "Allow" principals { type = "Service" identifiers = ["lambda.amazonaws.com"] } actions = ["sts:AssumeRole"] } }
resource "aws_iam_role" "iam_for_lambda" { name = "iam_for_lambda" assume_role_policy = data.aws_iam_policy_document.assume_role.json }
data "archive_file" "lambda" { type = "zip" source_file = "lambda.js" output_path = "lambda_function_payload.zip" }
resource "aws_lambda_function" "test_lambda" { # If the file is not in the current working directory you will need to include a # path.module in the filename. filename = "lambda_function_payload.zip" function_name = "lambda_function_name" role = aws_iam_role.iam_for_lambda.arn handler = "index.test" source_code_hash = data.archive_file.lambda.output_base64sha256
runtime = "nodejs18.x"
environment { variables = { foo = "bar" } }
}
Related[edit]
See also[edit]
Advertising: