-
-
Save qafro1/d2bc388ca341d2bfbbf592e31b3e8fcc to your computer and use it in GitHub Desktop.
lambda terraform
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
# Set the region where the lambda function will be created | |
variable "aws_region" { | |
default = "us-east-1" | |
} | |
# Assign the region to the provider in this case AWS | |
provider "aws" { | |
region = "${var.aws_region}" | |
} | |
# Archive the code or project that we want to run | |
data "archive_file" "lambda_zip" { | |
type = "zip" | |
source_file = "index.js" | |
output_path = "lambda_function.zip" | |
} | |
# Create the function | |
resource "aws_lambda_function" "test_lambda" { | |
filename = "lambda_function.zip" | |
function_name = "test_lambda" | |
role = "${aws_iam_role.iam_for_lambda_tf.arn}" | |
handler = "index.handler" | |
source_code_hash = "${data.archive_file.lambda_zip.output_base64sha256}" | |
runtime = "nodejs8.10" | |
} | |
# Necessary permissions to create/run the function | |
resource "aws_iam_role" "iam_for_lambda_tf" { | |
name = "iam_for_lambda_tf" | |
assume_role_policy = <<EOF | |
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Action": "sts:AssumeRole", | |
"Principal": { | |
"Service": "lambda.amazonaws.com" | |
}, | |
"Effect": "Allow", | |
"Sid": "" | |
} | |
] | |
} | |
EOF | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment