This file contains 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_iam_role_policy_attachment" "attach_policy_to_role" { | |
role = aws_iam_role.lambda_role.name | |
policy_arn = aws_iam_policy.lambda_policy.arn | |
} |
This file contains 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_iam_role" "lambda_role" { | |
name = "${local.lambda_function_name_prefix}-lambda-role" | |
assume_role_policy = data.aws_iam_policy_document.assume_role.json | |
} |
This file contains 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_iam_policy" "lambda_policy" { | |
name = "${local.lambda_function_name_prefix}-lambda-policy" | |
policy = <<EOF | |
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Effect": "Allow", | |
"Action": "logs:CreateLogGroup", |
This file contains 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
data "aws_iam_policy_document" "assume_role" { | |
statement { | |
effect = "Allow" | |
principals { | |
type = "Service" | |
identifiers = ["lambda.amazonaws.com"] | |
} | |
actions = ["sts:AssumeRole"] |
This file contains 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
output "api_gw_invoke_url" { | |
description = "The API Gateway Stage Invoke URL" | |
value = aws_api_gateway_stage.stage.invoke_url | |
} |
This file contains 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 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 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 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 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" { |