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_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 | |
] |
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_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, |
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
# 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 |
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
# 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 |
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
# 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" { |
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_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 | |
} |
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_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" | |
} |
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_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 | |
} |
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_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}/*/*" | |
} |
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_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"] | |
} | |
} |