Skip to content

Instantly share code, notes, and snippets.

@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" {
@nivleshc
nivleshc / blog-photo-location-map-api_gateway-05.tf
Created March 23, 2025 13:27
This gist contains code from the file api_gateway.tf which is part of the blog-photo-location-map repository.
resource "aws_api_gateway_integration" "fetch_object" {
rest_api_id = aws_api_gateway_rest_api.photo_location_map.id
resource_id = aws_api_gateway_resource.fetch_object.id
http_method = aws_api_gateway_method.fetch_object_get.http_method
integration_http_method = "POST"
type = "AWS_PROXY"
uri = aws_lambda_function.fetch_object_lambda.invoke_arn
}
@nivleshc
nivleshc / blog-photo-location-map-api_gateway-04.tf
Created March 23, 2025 13:24
This gist contains code from the file api_gateway.tf which is part of the blog-photo-location-map repository.
resource "aws_api_gateway_method" "fetch_object_get" {
rest_api_id = aws_api_gateway_rest_api.photo_location_map.id
resource_id = aws_api_gateway_resource.fetch_object.id
http_method = "GET"
authorization = "NONE"
}
@nivleshc
nivleshc / blog-photo-location-map-api_gateway-03.tf
Created March 23, 2025 13:21
This gist contains code from the file api_gateway.tf which is part of the blog-photo-location-map repository.
resource "aws_api_gateway_resource" "fetch_object" {
rest_api_id = aws_api_gateway_rest_api.photo_location_map.id
parent_id = aws_api_gateway_rest_api.photo_location_map.root_resource_id
path_part = local.api_gateway_fetch_object_path
}
@nivleshc
nivleshc / blog-photo-location-map-api_gateway-02.tf
Created March 23, 2025 13:17
This gist contains code from the file api_gateway.tf which is part of the blog-photo-location-map repository.
resource "aws_lambda_permission" "apigw_invoke_fetch_object_lambda" {
statement_id = "AllowAPIGatewayInvoke"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.fetch_object_lambda.function_name
principal = "apigateway.amazonaws.com"
source_arn = "${aws_api_gateway_rest_api.photo_location_map.execution_arn}/*/*"
}
@nivleshc
nivleshc / blog-photo-location-map-api_gateway-01.tf
Created March 23, 2025 13:11
This gist contains code from the file api_gateway.tf which is part of the blog-photo-location-map repository.
resource "aws_api_gateway_rest_api" "photo_location_map" {
name = "${local.api_gateway_rest_api_name_prefix}-api-gw"
description = "API Gateway to front lambdas used to plot photo locations on a map"
endpoint_configuration {
types = ["REGIONAL"]
}
}