Added lambda trigger
This commit is contained in:
47
master.tf
47
master.tf
@@ -74,7 +74,6 @@ data "aws_iam_policy_document" "s3_standout_allow_lambda" {
|
||||
}
|
||||
|
||||
# create a redirect lambda function
|
||||
|
||||
data "aws_iam_policy_document" "lambda_role" {
|
||||
statement {
|
||||
effect = "Allow"
|
||||
@@ -96,16 +95,16 @@ resource "aws_iam_role" "iam_for_lambda" {
|
||||
data "archive_file" "lambda_standout_code" {
|
||||
type = "zip"
|
||||
source_file = "./lambda_redirect/lambda_redirect.py"
|
||||
output_path = "standout_lambda_function.zip"
|
||||
output_path = "./lambda_redirect/standout_lambda_function.zip"
|
||||
}
|
||||
|
||||
resource "aws_lambda_function" "lambda_standout_redirect" {
|
||||
# If the file is not in the current working directory you will need to include a
|
||||
# path.module in the filename.
|
||||
filename = "standout_lambda_function.zip"
|
||||
filename = "./lambda_redirect/standout_lambda_function.zip"
|
||||
function_name = "standout-redirect"
|
||||
role = aws_iam_role.iam_for_lambda.arn
|
||||
handler = "lambda_handler"
|
||||
handler = "lambda_redirect.lambda_handler"
|
||||
|
||||
source_code_hash = data.archive_file.lambda_standout_code.output_base64sha256
|
||||
|
||||
@@ -118,5 +117,45 @@ resource "aws_lambda_function" "lambda_standout_redirect" {
|
||||
#}
|
||||
}
|
||||
|
||||
# create API gateway for lambda triger and connect
|
||||
resource "aws_apigatewayv2_api" "api_standout_gateway" {
|
||||
name = "standout-api"
|
||||
protocol_type = "HTTP"
|
||||
}
|
||||
|
||||
resource "aws_apigatewayv2_integration" "api_standout_integration" {
|
||||
api_id = aws_apigatewayv2_api.api_standout_gateway.id
|
||||
integration_type = "AWS_PROXY"
|
||||
|
||||
connection_type = "INTERNET"
|
||||
description = "Lambda example"
|
||||
integration_method = "POST"
|
||||
integration_uri = aws_lambda_function.lambda_standout_redirect.invoke_arn
|
||||
passthrough_behavior = "WHEN_NO_MATCH"
|
||||
}
|
||||
|
||||
resource "aws_apigatewayv2_stage" "api_standout_lambda_stage" {
|
||||
api_id = aws_apigatewayv2_api.api_standout_gateway.id
|
||||
|
||||
name = "dev"
|
||||
auto_deploy = true
|
||||
}
|
||||
|
||||
resource "aws_apigatewayv2_route" "api_standout_route" {
|
||||
api_id = aws_apigatewayv2_api.api_standout_gateway.id
|
||||
|
||||
route_key = "GET /api"
|
||||
target = "integrations/${aws_apigatewayv2_integration.api_standout_integration.id}"
|
||||
}
|
||||
|
||||
resource "aws_lambda_permission" "api_lambda_permission" {
|
||||
statement_id = "AllowExecutionFromAPIGateway"
|
||||
action = "lambda:InvokeFunction"
|
||||
function_name = aws_lambda_function.lambda_standout_redirect.function_name
|
||||
principal = "apigateway.amazonaws.com"
|
||||
|
||||
source_arn = "${aws_apigatewayv2_api.api_standout_gateway.execution_arn}/*/*"
|
||||
}
|
||||
|
||||
# create a route 53 configuration
|
||||
|
||||
|
||||
Reference in New Issue
Block a user