-
-
Save pt-arvind/9c6e2da90ff2039f9e47fdb552e1e629 to your computer and use it in GitHub Desktop.
"Hello World" AWS Lambda + Terraform Example
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
// 'Hello World' nodejs6.10 runtime AWS Lambda function | |
exports.handler = (event, context, callback) => { | |
console.log('Hello, logs!'); | |
callback(null, 'great success'); | |
} |
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
# Simple AWS Lambda Terraform Example | |
# requires 'index.js' in the same directory | |
# to test: run `terraform plan` | |
# to deploy: run `terraform apply` | |
variable "aws_region" { | |
default = "us-west-2" | |
} | |
provider "aws" { | |
region = "${var.aws_region}" | |
} | |
data "archive_file" "lambda_zip" { | |
type = "zip" | |
source_file = "index.js" | |
output_path = "lambda_function.zip" | |
} | |
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 = "nodejs6.10" | |
} | |
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