Skip to content

Instantly share code, notes, and snippets.

@nivleshc
nivleshc / blog-photo-location-map-lambda-08.tf
Created March 26, 2025 23:57
This gist contains code from the file lambda.tf which is part of the blog-photo-location-map repository.
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
@nivleshc
nivleshc / blog-photo-location-map-lambda-07.tf
Created March 26, 2025 23:08
This gist contains code from the file lambda.tf which is part of the blog-photo-location-map repository.
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")
}
@nivleshc
nivleshc / blog-photo-location-map-package-python-libraries-01.sh
Created March 25, 2025 22:53
This gist contains code for packaging the python libraries used to create the AWS Lambda layer that will be used by the AWS Lambda functions in the blog-photo-location-map repository.
mkdir lambda_layer/python
cd lambda_layer
pip install cffi cryptography PyJWT pillow folium -t ./python
zip -r layer-photo-location-map.zip python/
@nivleshc
nivleshc / blog-photo-location-map-lambda-06.tf
Created March 25, 2025 22:44
This gist contains code from the file lambda.tf which is part of the blog-photo-location-map repository.
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"
@nivleshc
nivleshc / blog-photo-location-map-lambda-05.tf
Created March 25, 2025 22:37
This gist contains code from the file lambda.tf which is part of the blog-photo-location-map repository.
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
}
@nivleshc
nivleshc / blog-photo-location-map-lambda-04.tf
Created March 25, 2025 22:31
This gist contains code from the file lambda.tf which is part of the blog-photo-location-map repository.
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
}
@nivleshc
nivleshc / blog-photo-location-map-lambda-03.tf
Created March 25, 2025 22:20
This gist contains code from the file lambda.tf which is part of the blog-photo-location-map repository.
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
}
@nivleshc
nivleshc / blog-photo-location-map-lambda-02.tf
Created March 25, 2025 21:31
This gist contains code from the file lambda.tf which is part of the blog-photo-location-map repository.
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",
@nivleshc
nivleshc / blog-photo-location-map-lambda-01.tf
Created March 25, 2025 21:28
This gist contains code from the file lambda.tf which is part of the blog-photo-location-map repository.
data "aws_iam_policy_document" "assume_role" {
statement {
effect = "Allow"
principals {
type = "Service"
identifiers = ["lambda.amazonaws.com"]
}
actions = ["sts:AssumeRole"]
@nivleshc
nivleshc / blog-photo-location-map-api_gateway-11.tf
Created March 23, 2025 23:42
This gist contains code from the file api_gateway.tf which is part of the blog-photo-location-map repository.
output "api_gw_invoke_url" {
description = "The API Gateway Stage Invoke URL"
value = aws_api_gateway_stage.stage.invoke_url
}