Skip to content

Instantly share code, notes, and snippets.

@sagespidy
Forked from smithclay/index.js
Created October 2, 2018 05:34
Show Gist options
  • Save sagespidy/400db584d2220ca01aec80a56f4fb0bd to your computer and use it in GitHub Desktop.
Save sagespidy/400db584d2220ca01aec80a56f4fb0bd to your computer and use it in GitHub Desktop.
"Hello World" AWS Lambda + Terraform Example
// 'Hello World' nodejs6.10 runtime AWS Lambda function
exports.handler = (event, context, callback) => {
console.log('Hello, logs!');
callback(null, 'great success');
}
# 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