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

added lambda provisionning

parent 52be5bf0
No related branches found
No related tags found
No related merge requests found
......@@ -61,7 +61,7 @@ resource "aws_iam_role_policy_attachment" "lambda_apigw" {
}
resource "aws_iam_policy" "apigw_read_only" {
name = "ApiGatewayReadOnly"
name = "${local.prefix}-ApiGatewayReadOnly"
path = "/"
description = "Read only for describing APIGateway services"
# Terraform's "jsonencode" function converts a
......
......@@ -9,9 +9,10 @@ resource "aws_lambda_function" "crud" {
role = aws_iam_role.iam_for_lambda.arn
handler = "${each.key}.handler"
timeout = 10
source_code_hash = filebase64sha256(data.archive_file.lambda_file.output_path)
source_code_hash = data.archive_file.lambda_file.output_base64sha256
runtime = "nodejs12.x"
reserved_concurrent_executions = 2
publish = true
layers = [
"arn:aws:lambda:eu-west-1:580247275435:layer:LambdaInsightsExtension:14"
]
......@@ -36,7 +37,7 @@ resource "aws_lambda_function" "index" {
role = aws_iam_role.iam_for_lambda.arn
handler = "index.handler"
timeout = 10
source_code_hash = filebase64sha256(data.archive_file.lambda_index_file.output_path)
source_code_hash = data.archive_file.lambda_index_file.output_base64sha256
runtime = "nodejs12.x"
reserved_concurrent_executions = 2
layers = [
......@@ -46,6 +47,10 @@ resource "aws_lambda_function" "index" {
tags = local.common_tags
}
###############
# Permissions #
###############
resource "aws_iam_role" "iam_for_lambda" {
name = "${local.prefix}-lambda"
assume_role_policy = file("./templates/lambda/assume-role-policy.json")
......@@ -75,6 +80,10 @@ resource "aws_iam_role_policy_attachment" "lambda_insights" {
policy_arn = "arn:aws:iam::aws:policy/CloudWatchLambdaInsightsExecutionRolePolicy"
}
#########
# Files #
#########
data "archive_file" "lambda_file" {
type = "zip"
output_path = "${local.lambda_loc}/zip/lambda.zip"
......@@ -86,3 +95,14 @@ data "archive_file" "lambda_index_file" {
output_path = "${local.lambda_loc}/zip/index.zip"
source_file = "${local.lambda_loc}/src/index.js"
}
#################
# Provisionning #
#################
resource "aws_lambda_provisioned_concurrency_config" "crud" {
for_each = local.lambdas
function_name = aws_lambda_function.crud[each.key].function_name
provisioned_concurrent_executions = 1
qualifier = aws_lambda_function.crud[each.key].version
}
......@@ -5,6 +5,7 @@ const {v4:uuidv4} = require('uuid');
const TABLE_NAME = process.env.TABLE_NAME || '';
const PRIMARY_KEY = process.env.TABLE_KEY || '';
const RESERVED_RESPONSE = `Error: You're using AWS reserved keywords as attributes`, DYNAMODB_EXECUTION_ERROR = `Error: Execution update, caused a Dynamodb error, please take a look at your CloudWatch Logs.`;
exports.handler = async (event = {}) => {
console.log(event)
if (!event.body) {
......
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