Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
"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

This comment has been minimized.

Copy link

@maheshrajanna maheshrajanna commented Sep 4, 2020

Thank you

@bnathreddy1

This comment has been minimized.

Copy link

@bnathreddy1 bnathreddy1 commented Jun 4, 2021

thank you very much

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