This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "aws_lambda_function" "fetch_object_lambda" { | |
filename = data.archive_file.fetch_object_lambda_src.output_path | |
function_name = "${local.lambda_function_name_prefix}-fetch-object-lambda" | |
timeout = local.lambda_function_timeout | |
role = aws_iam_role.lambda_role.arn | |
handler = "fetch-object-lambda.lambda_handler" | |
source_code_hash = data.archive_file.fetch_object_lambda_src.output_base64sha256 | |
runtime = local.lambda_runtime |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "aws_lambda_layer_version" "photo_location_map_layer" { | |
filename = "${path.module}/src/layers/layer-photo-location-map.zip" | |
layer_name = "layer_photo_location_map" | |
description = "Lambda layer containing cffi cryptography PyJWT pillow folium python packages" | |
compatible_runtimes = local.lambda_layer_compatibe_runtimes | |
source_code_hash = filebase64sha256("${path.module}/src/layers/layer-photo-location-map.zip") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mkdir lambda_layer/python | |
cd lambda_layer | |
pip install cffi cryptography PyJWT pillow folium -t ./python | |
zip -r layer-photo-location-map.zip python/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data "archive_file" "fetch_object_lambda_src" { | |
type = "zip" | |
source_file = "${path.module}/src/function/fetch-object-lambda.py" | |
output_path = "${path.module}/src/function/fetch-object-lambda.zip" | |
} | |
data "archive_file" "upload_photo_lambda_src" { | |
type = "zip" | |
source_file = "${path.module}/src/function/upload-photo-lambda.py" | |
output_path = "${path.module}/src/function/upload-photo-lambda.zip" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "aws_cloudwatch_log_group" "fetch_object_lambda_loggroup" { | |
name = "/aws/lambda/${local.lambda_function_name_prefix}-fetch-object-lambda" | |
retention_in_days = local.lambda_cloudwatch_log_group_retention | |
} | |
resource "aws_cloudwatch_log_group" "upload_photo_lambda_loggroup" { | |
name = "/aws/lambda/${local.lambda_function_name_prefix}-upload-photo-lambda" | |
retention_in_days = local.lambda_cloudwatch_log_group_retention | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "aws_iam_role_policy_attachment" "attach_policy_to_role" { | |
role = aws_iam_role.lambda_role.name | |
policy_arn = aws_iam_policy.lambda_policy.arn | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "aws_iam_role" "lambda_role" { | |
name = "${local.lambda_function_name_prefix}-lambda-role" | |
assume_role_policy = data.aws_iam_policy_document.assume_role.json | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "aws_iam_policy" "lambda_policy" { | |
name = "${local.lambda_function_name_prefix}-lambda-policy" | |
policy = <<EOF | |
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Effect": "Allow", | |
"Action": "logs:CreateLogGroup", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data "aws_iam_policy_document" "assume_role" { | |
statement { | |
effect = "Allow" | |
principals { | |
type = "Service" | |
identifiers = ["lambda.amazonaws.com"] | |
} | |
actions = ["sts:AssumeRole"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
output "api_gw_invoke_url" { | |
description = "The API Gateway Stage Invoke URL" | |
value = aws_api_gateway_stage.stage.invoke_url | |
} |