Difference between revisions of "Terraform resource: aws lambda function"

From wikieduonline
Jump to navigation Jump to search
Line 3: Line 3:
  
 
== Official example ==
 
== Official example ==
<pre>
+
 
data "aws_iam_policy_document" "assume_role" {
+
data "[[aws_iam_policy_document]]" "assume_role" {
 
   statement {
 
   statement {
 
     effect = "Allow"
 
     effect = "Allow"
Line 14: Line 14:
  
 
     actions = ["sts:AssumeRole"]
 
     actions = ["sts:AssumeRole"]
  }
+
  }
}
+
}
  
 
resource "aws_iam_role" "iam_for_lambda" {
 
resource "aws_iam_role" "iam_for_lambda" {

Revision as of 15:02, 23 July 2024

aws_lambda_function

Official example

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

See also

Advertising: