Skip to content

Instantly share code, notes, and snippets.

@nivleshc
nivleshc / blog-photo-location-map-photo_location_map_webpage.tf
Created June 9, 2025 08:38
This gist contains code from the file photo_location_map_webpage.tf which is part of the blog-photo-location-map repository.
# create the webpage that will be used to interact with this solution
resource "local_file" "index_html" {
content = templatefile("${path.module}/tpl/index.tftpl",
{ user_pool_id = aws_cognito_user_pool.user_pool.id,
client_id = aws_cognito_user_pool_client.user_pool_client.id,
api_gw_fetch_object_url = "${aws_api_gateway_stage.stage.invoke_url}/${local.api_gateway_fetch_object_path}${local.cognito_callback_url_suffix}",
api_gw_upload_photo_url = "${aws_api_gateway_stage.stage.invoke_url}/${local.api_gateway_upload_photo_path}${local.cognito_callback_url_suffix}",
api_gw_regenerate_map_url = "${aws_api_gateway_stage.stage.invoke_url}/${local.api_gateway_regenerate_map_path}${local.cognito_callback_url_suffix}"
})
filename = "${path.module}/${local.local_webpage_path}"
@nivleshc
nivleshc / blog-photo-location-map-locals.tf
Created June 9, 2025 08:36
This gist contains code from the file locals.tf which is part of the blog-photo-location-map repository.
locals {
account_id = data.aws_caller_identity.current.account_id
region = "ap-southeast-2"
lambda_function_name_prefix = "photo-location-map"
lambda_cloudwatch_log_group_retention = 7
lambda_runtime = "python3.13"
lambda_function_timeout = 300 # in seconds
lambda_handler = "lambda_function.lambda_handler"
lambda_layer_compatibe_runtimes = ["python3.13"]
@nivleshc
nivleshc / blog-photo-location-map-provider.tf
Created June 9, 2025 08:33
This gist contains code from the file provider.tf which is part of the blog-photo-location-map repository.
provider "aws" {
region = local.region
default_tags {
tags = {
Project = local.lambda_function_name_prefix
}
}
}
@nivleshc
nivleshc / blog-photo-location-map-s3.tf
Created June 9, 2025 08:31
This gist contains code from the file s3.tf which is part of the blog-photo-location-map repository.
resource "aws_s3_bucket" "website_s3_bucket" {
bucket = local.website_s3_bucket_name
}
@nivleshc
nivleshc / blog-photo-location-map-data.tf
Created June 9, 2025 08:25
This gist contains code from the file data.tf which is part of the blog-photo-location-map repository.
data "aws_caller_identity" "current" {}
@nivleshc
nivleshc / blog-photo-location-map-regenerate-map-lambda.py
Created March 27, 2025 00:36
This gist contains code from the file regenerate-map-lambda.py which is part of the blog-photo-location-map repository.
import os
import io
import csv
import boto3
import json
import folium
import jwt
from jwt import PyJWKClient
from PIL import Image, ExifTags
@nivleshc
nivleshc / blog-photo-location-map-upload-photo-lambda.py
Created March 27, 2025 00:26
This gist contains code from the file upload-photo-lambda.py which is part of the blog-photo-location-map repository.
import os
import json
import base64
import boto3
import csv
import io
import jwt
from jwt import PyJWKClient
from PIL import Image, ExifTags
@nivleshc
nivleshc / blog-photo-location-map-fetch-object-lambda.py
Created March 27, 2025 00:14
This gist contains code from the file fetch-object-lambda.py which is part of the blog-photo-location-map repository.
import os
import json
import boto3
import urllib.request
import jwt
from jwt import PyJWKClient
# retrieve environment variables
s3_bucket = os.environ.get('BUCKET_NAME') # S3 bucket that contains all the objects
cognito_pool_id = os.environ.get('COGNITO_POOL_ID') # Cognito User Pool ID used for authentication
@nivleshc
nivleshc / blog-photo-location-map-lambda-10.tf
Created March 27, 2025 00:02
This gist contains code from the file lambda.tf which is part of the blog-photo-location-map repository.
resource "aws_lambda_function" "regenerate_map_lambda" {
filename = data.archive_file.regenerate_map_lambda_src.output_path
function_name = "${local.lambda_function_name_prefix}-regenerate-map-lambda"
timeout = local.lambda_function_timeout
role = aws_iam_role.lambda_role.arn
handler = "regenerate-map-lambda.lambda_handler"
source_code_hash = data.archive_file.regenerate_map_lambda_src.output_base64sha256
runtime = local.lambda_runtime
@nivleshc
nivleshc / blog-photo-location-map-lambda-09.tf
Created March 27, 2025 00:00
This gist contains code from the file lambda.tf which is part of the blog-photo-location-map repository.
resource "aws_lambda_function" "upload_photo_lambda" {
filename = data.archive_file.upload_photo_lambda_src.output_path
function_name = "${local.lambda_function_name_prefix}-upload-photo-lambda"
timeout = local.lambda_function_timeout
role = aws_iam_role.lambda_role.arn
handler = "upload-photo-lambda.lambda_handler"
source_code_hash = data.archive_file.upload_photo_lambda_src.output_base64sha256
runtime = local.lambda_runtime