Compare commits
1 Commits
4ba240c062
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 729ecaae1c |
@@ -133,3 +133,53 @@ resource "aws_iam_role_policy" "dynamodb_access" {
|
|||||||
locals {
|
locals {
|
||||||
table_name = var.table_name != "" ? var.table_name : "pathfinder-${var.environment}-pricing"
|
table_name = var.table_name != "" ? var.table_name : "pathfinder-${var.environment}-pricing"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# API Gateway HTTP API
|
||||||
|
resource "aws_apigatewayv2_api" "crud_pricing_api" {
|
||||||
|
name = "airun-pathfinder-crud-pricing-${var.environment}"
|
||||||
|
protocol_type = "HTTP"
|
||||||
|
|
||||||
|
cors_configuration {
|
||||||
|
allow_origins = ["*"]
|
||||||
|
allow_methods = ["GET", "POST", "PUT", "OPTIONS"]
|
||||||
|
allow_headers = ["*"]
|
||||||
|
}
|
||||||
|
|
||||||
|
tags = {
|
||||||
|
Name = "crud-pricing-api"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_apigatewayv2_stage" "default" {
|
||||||
|
api_id = aws_apigatewayv2_api.crud_pricing_api.id
|
||||||
|
name = "$default"
|
||||||
|
auto_deploy = true
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_apigatewayv2_integration" "lambda" {
|
||||||
|
api_id = aws_apigatewayv2_api.crud_pricing_api.id
|
||||||
|
integration_type = "AWS_PROXY"
|
||||||
|
integration_uri = aws_lambda_function.crud_pricing.invoke_arn
|
||||||
|
integration_method = "POST"
|
||||||
|
payload_format_version = "2.0"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_apigatewayv2_route" "pricing_instance" {
|
||||||
|
api_id = aws_apigatewayv2_api.crud_pricing_api.id
|
||||||
|
route_key = "GET /pricing/{instanceType}"
|
||||||
|
target = "integrations/${aws_apigatewayv2_integration.lambda.id}"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_apigatewayv2_route" "pricing_list" {
|
||||||
|
api_id = aws_apigatewayv2_api.crud_pricing_api.id
|
||||||
|
route_key = "GET /pricing"
|
||||||
|
target = "integrations/${aws_apigatewayv2_integration.lambda.id}"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_lambda_permission" "api_gateway" {
|
||||||
|
statement_id = "AllowAPIGatewayInvoke"
|
||||||
|
action = "lambda:InvokeFunction"
|
||||||
|
function_name = aws_lambda_function.crud_pricing.function_name
|
||||||
|
principal = "apigateway.amazonaws.com"
|
||||||
|
source_arn = "${aws_apigatewayv2_api.crud_pricing_api.execution_arn}/*/*"
|
||||||
|
}
|
||||||
|
|||||||
@@ -17,3 +17,8 @@ output "table_name" {
|
|||||||
description = "DynamoDB table name used by this Lambda"
|
description = "DynamoDB table name used by this Lambda"
|
||||||
value = local.table_name
|
value = local.table_name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
output "api_gateway_endpoint" {
|
||||||
|
description = "API Gateway endpoint URL"
|
||||||
|
value = aws_apigatewayv2_api.crud_pricing_api.api_endpoint
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user