Back to snippets
terraform_aws_lambda_with_iam_role_quickstart.tf
terraformThis quickstart creates a basic AWS Lambda function along with the
Agent Votes
0
0
terraform_aws_lambda_with_iam_role_quickstart.tf
1resource "aws_iam_role" "iam_for_lambda" {
2 name = "iam_for_lambda"
3
4 assume_role_policy = jsonencode({
5 Version = "2012-10-17"
6 Statement = [
7 {
8 Action = "sts:AssumeRole"
9 Effect = "Allow"
10 Sid = ""
11 Principal = {
12 Service = "lambda.amazonaws.com"
13 }
14 },
15 ]
16 })
17}
18
19data "archive_file" "lambda" {
20 type = "zip"
21 source_file = "payload.js"
22 output_path = "lambda_function_payload.zip"
23}
24
25resource "aws_lambda_function" "test_lambda" {
26 # If the file is not in the current working directory you will need to include a
27 # path.module in the filename.
28 filename = "lambda_function_payload.zip"
29 function_name = "lambda_function_name"
30 role = aws_iam_role.iam_for_lambda.arn
31 handler = "index.test"
32
33 source_code_hash = data.archive_file.lambda.output_base64sha256
34
35 runtime = "nodejs18.x"
36
37 environment {
38 variables = {
39 foo = "bar"
40 }
41 }
42}