Skip to content
Snippets Groups Projects
Commit 786703c8 authored by Edouard DE BRYE's avatar Edouard DE BRYE
Browse files

Merge branch 'feature/create-lambda' into 'master'

Added lambda hello world

See merge request edebrye/cloud-monitor!2
parents f1e808b5 b26dba63
No related merge requests found
......@@ -31,4 +31,6 @@ override.tf.json
# Ignore CLI configuration files
.terraformrc
terraform.rc
\ No newline at end of file
terraform.rc
**/lambda_zip/*
\ No newline at end of file
.PHONY:lambda
lambda:
cd lambda/hello && zip -r hello.zip index.js && mv hello.zip ../../deploy/lambda_zip
variable "lambda_filename" {
default = "./lambda_zip/hello.zip"
type = string
}
resource "aws_lambda_function" "test_lambda" {
filename = var.lambda_filename
function_name = "${local.prefix}-hello"
role = aws_iam_role.iam_for_lambda.arn
handler = "index.handler"
# The filebase64sha256() function is available in Terraform 0.11.12 and later
# For Terraform 0.11.11 and earlier, use the base64sha256() function and the file() function:
# source_code_hash = "${base64sha256(file("lambda_function_payload.zip"))}"
source_code_hash = filebase64sha256(var.lambda_filename)
runtime = "nodejs14.x"
reserved_concurrent_executions = 2
tags = local.common_tags
}
resource "aws_iam_role" "iam_for_lambda" {
name = "${local.prefix}-lambda"
assume_role_policy = file("./templates/lambda/assume-role-policy.json")
}
# See also the following AWS managed policy: AWSLambdaBasicExecutionRole
resource "aws_iam_policy" "lambda_logging" {
name = "${local.prefix}-lambda_logging"
path = "/"
description = "IAM policy for logging from a lambda"
policy = file("./templates/lambda/lambda-policy.json")
}
resource "aws_iam_role_policy_attachment" "lambda_logs" {
role = aws_iam_role.iam_for_lambda.name
policy_arn = aws_iam_policy.lambda_logging.arn
}
\ No newline at end of file
......@@ -38,6 +38,6 @@ resource "aws_vpc" "main" {
tags = merge(
local.common_tags,
map("Name","${local.prefix}-main")
map("Name", "${local.prefix}-main")
)
}
\ No newline at end of file
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
\ No newline at end of file
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:*:*:*",
"Effect": "Allow"
}
]
}
\ No newline at end of file
exports.handler = async (event,context) => {
// TODO implement
console.log("ENVIRONMENT VARIABLES\n" + JSON.stringify(process.env, null, 2))
console.info("EVENT\n" + JSON.stringify(event, null, 2))
console.warn("Event not processed.")
console.log("CONTEXT\n" + JSON.stringify(context,null,2))
const response = {
statusCode: 200,
body: JSON.stringify('Hello from Lambda!'),
logStream: context.logStreamName
};
return response;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment