Skip to content

Instantly share code, notes, and snippets.

@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
}
@nivleshc
nivleshc / blog-photo-location-map-api_gateway-10.tf
Created March 23, 2025 23:40
This gist contains code from the file api_gateway.tf which is part of the blog-photo-location-map repository.
resource "aws_api_gateway_stage" "stage" {
deployment_id = aws_api_gateway_deployment.photo_location_map_deployment.id
rest_api_id = aws_api_gateway_rest_api.photo_location_map.id
stage_name = local.api_gateway_stage_name
depends_on = [
aws_api_gateway_integration.fetch_object,
aws_api_gateway_integration.upload_photo,
aws_api_gateway_integration.regenerate_map
]
@nivleshc
nivleshc / blog-photo-location-map-api_gateway-09.tf
Created March 23, 2025 23:37
This gist contains code from the file api_gateway.tf which is part of the blog-photo-location-map repository.
resource "aws_api_gateway_deployment" "photo_location_map_deployment" {
rest_api_id = aws_api_gateway_rest_api.photo_location_map.id
lifecycle {
create_before_destroy = true
}
depends_on = [
aws_api_gateway_integration.fetch_object,
aws_api_gateway_integration.upload_photo,
@nivleshc
nivleshc / blog-photo-location-map-api_gateway-08.tf
Created March 23, 2025 23:34
This gist contains code from the file api_gateway.tf which is part of the blog-photo-location-map repository.
# Allow API Gateway to invoke the regenerate-map lambda function
resource "aws_lambda_permission" "apigw_invoke_regenerate_map_lambda" {
statement_id = "AllowAPIGatewayInvoke"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.regenerate_map_lambda.function_name
principal = "apigateway.amazonaws.com"
source_arn = "${aws_api_gateway_rest_api.photo_location_map.execution_arn}/*/*"
}
# create the resource for regenerating map
@nivleshc
nivleshc / blog-photo-location-map-api_gateway-07.tf
Created March 23, 2025 22:23
This gist contains code from the file api_gateway.tf which is part of the blog-photo-location-map repository.
# Allow API Gateway to invoke the upload-photo lambda function
resource "aws_lambda_permission" "apigw_invoke_upload_photo_lambda" {
statement_id = "AllowAPIGatewayInvoke"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.upload_photo_lambda.function_name
principal = "apigateway.amazonaws.com"
source_arn = "${aws_api_gateway_rest_api.photo_location_map.execution_arn}/*/*"
}
# create the resource for uploading photo
@nivleshc
nivleshc / blog-photo-location-map-api_gateway-06.tf
Created March 23, 2025 13:41
This gist contains code from the file api_gateway.tf which is part of the blog-photo-location-map repository.
# Create CORS for fetch-object using OPTIONS method
resource "aws_api_gateway_method" "fetch_object_options" {
rest_api_id = aws_api_gateway_rest_api.photo_location_map.id
resource_id = aws_api_gateway_resource.fetch_object.id
http_method = "OPTIONS"
authorization = "NONE"
}
# Set up a MOCK integration for the OPTIONS method.
resource "aws_api_gateway_integration" "fetch_object_options_integration" {