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

Merge branch 'feature/add-monitoring-to-hello-lambda' into 'master'

Added lambda insights for more informations to hello world lambda

See merge request edebrye/cloud-monitor!3
parents 786703c8 2ebb7650
No related branches found
No related tags found
No related merge requests found
......@@ -33,4 +33,4 @@ override.tf.json
.terraformrc
terraform.rc
**/lambda_zip/*
\ No newline at end of file
*.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
# This file is maintained automatically by "terraform init".
# Manual edits may be lost in future updates.
provider "registry.terraform.io/hashicorp/archive" {
version = "2.1.0"
hashes = [
"h1:f3WXKM/FBu5EMY6j2BGt982hzVMNicrxTyEAz5EsrOU=",
"zh:033279ecbf60f565303222e9a6d26b50fdebe43aa1c6e8f565f09bb64d67c3fd",
"zh:0af998e42eb421c92e87202df5bfee436b3cfe553214394f08d786c72a9e3f70",
"zh:1183b661c692f38409a61eefb5d412167c246fcd9e49d4d61d6d910012d206ba",
"zh:5febb66f4a8207117f71dcd460fb9c81d3afb7b600b5e598cf517cf6e27cf4b2",
"zh:66135ce46d29d0ccf0e3b6a119423754ca334dbf4266bc989cce5b0b667b5fde",
"zh:6b9dc1a4f0a680bb650a7191784927f99675a8c8dd3c155ba821185f630db604",
"zh:91e249482c016ecf6bf8b83849964005cd2d0b4396688419cd1752809b46b23e",
"zh:a6a2e5f2f010c511e66174cb84ea18899e8bcfc1354c4b9fed972fdb131ffffc",
"zh:bb1f6abc76552a883732caff897ff7b07a91977a9b4bb97915f6aac54116bb65",
"zh:f05a9a63607f85719fde705f58d82ee16fa67f9158a5c3424c0216507631eddf",
"zh:fc603a05a06814387ffa4a054d1baee8ea6b5ab32c53cb73e90a5bf9a2616777",
]
}
provider "registry.terraform.io/hashicorp/aws" {
version = "3.30.0"
constraints = ">= 3.30.0"
......
variable "lambda_filename" {
default = "./lambda_zip/hello.zip"
default = "hello/index.js"
type = string
}
variable "lambda_loc" {
default = "lambda"
type = string
}
variable "layer_name" {
type = string
default = "LambdaInsightsExtension"
}
resource "aws_lambda_function" "test_lambda" {
filename = var.lambda_filename
filename = data.archive_file.lambda_file.output_path
function_name = "${local.prefix}-hello"
role = aws_iam_role.iam_for_lambda.arn
handler = "index.handler"
......@@ -12,12 +22,19 @@ resource "aws_lambda_function" "test_lambda" {
# 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)
source_code_hash = filebase64sha256(data.archive_file.lambda_file.output_path)
runtime = "nodejs14.x"
reserved_concurrent_executions = 2
layers = [
"arn:aws:lambda:eu-west-1:580247275435:layer:LambdaInsightsExtension:14"
]
tags = local.common_tags
depends_on = [
data.archive_file.lambda_file
]
}
resource "aws_iam_role" "iam_for_lambda" {
......@@ -38,4 +55,15 @@ resource "aws_iam_policy" "lambda_logging" {
resource "aws_iam_role_policy_attachment" "lambda_logs" {
role = aws_iam_role.iam_for_lambda.name
policy_arn = aws_iam_policy.lambda_logging.arn
}
resource "aws_iam_role_policy_attachment" "lambda_insights" {
role = aws_iam_role.iam_for_lambda.name
policy_arn = "arn:aws:iam::aws:policy/CloudWatchLambdaInsightsExecutionRolePolicy"
}
data "archive_file" "lambda_file" {
type = "zip"
source_file = "${var.lambda_loc}/${var.lambda_filename}"
output_path = "${var.lambda_loc}/lambda.zip"
}
\ No newline at end of file
File moved
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