Skip to content

Instantly share code, notes, and snippets.

@smithclay
Created June 16, 2017 18:30
Show Gist options
  • Star 39 You must be signed in to star a gist
  • Fork 18 You must be signed in to fork a gist
  • Save smithclay/e026b10980214cbe95600b82f67b4958 to your computer and use it in GitHub Desktop.
Save smithclay/e026b10980214cbe95600b82f67b4958 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
}
@maheshrajanna
Copy link

Thank you

@bnathreddy1
Copy link

thank you very much

@ikushlianski
Copy link

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment