Guys, im trying to create an api, but just can’t create an integration response for my post method
resource "aws_api_gateway_rest_api" "api" {
name = "example-api"
description = "API integration for Lambda"
endpoint_configuration {
types = ["REGIONAL"]
}
}
resource "aws_api_gateway_resource" "resource" {
rest_api_id = aws_api_gateway_rest_api.api.id
parent_id = aws_api_gateway_rest_api.api.root_resource_id
path_part = "lambda-function-s3"
}
resource "aws_api_gateway_method" "options" {
rest_api_id = aws_api_gateway_rest_api.api.id
resource_id = aws_api_gateway_resource.resource.id
http_method = "OPTIONS"
authorization = "NONE"
}
resource "aws_api_gateway_integration" "options" {
rest_api_id = aws_api_gateway_rest_api.api.id
resource_id = aws_api_gateway_resource.resource.id
http_method = aws_api_gateway_method.options.http_method
type = "MOCK"
integration_http_method = "OPTIONS"
passthrough_behavior = "WHEN_NO_MATCH"
}
resource "aws_api_gateway_method_response" "options_200" {
rest_api_id = aws_api_gateway_rest_api.api.id
resource_id = aws_api_gateway_resource.resource.id
http_method = aws_api_gateway_method.options.http_method
status_code = "200"
response_models = {
"application/json" = "Empty"
}
response_parameters = {
"method.response.header.Access-Control-Allow-Headers" = true
"method.response.header.Access-Control-Allow-Methods" = true
"method.response.header.Access-Control-Allow-Origin" = true
}
}
resource "aws_api_gateway_integration_response" "options_200" {
rest_api_id = aws_api_gateway_rest_api.api.id
resource_id = aws_api_gateway_resource.resource.id
http_method = aws_api_gateway_method.options.http_method
status_code = aws_api_gateway_method_response.options_200.status_code
selection_pattern = "-"
content_handling = "CONVERT_TO_TEXT"
response_parameters = {
"method.response.header.Access-Control-Allow-Headers" = "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'"
"method.response.header.Access-Control-Allow-Methods" = "'GET,POST,OPTIONS'"
"method.response.header.Access-Control-Allow-Origin" = "'*'"
}
}
resource "aws_api_gateway_method" "post" {
rest_api_id = aws_api_gateway_rest_api.api.id
resource_id = aws_api_gateway_resource.resource.id
http_method = "POST"
authorization = "NONE"
}
resource "aws_api_gateway_integration" "post" {
rest_api_id = aws_api_gateway_rest_api.api.id
resource_id = aws_api_gateway_resource.resource.id
http_method = aws_api_gateway_method.post.http_method
integration_http_method = "POST"
type = "AWS"
uri = "arn:aws:apigateway:${var.aws_region}:lambda:path/2015-03-31/functions/${aws_lambda_function.my_lambda.arn}/invocations"
passthrough_behavior = "WHEN_NO_MATCH"
timeout_milliseconds = 29000
}
resource "aws_api_gateway_method_response" "post_200" {
rest_api_id = aws_api_gateway_rest_api.api.id
resource_id = aws_api_gateway_resource.resource.id
http_method = aws_api_gateway_method.post.http_method
status_code = "200"
response_models = {
"application/json" = "Empty"
}
response_parameters = {
"method.response.header.Access-Control-Allow-Origin" = true
}
}
resource "aws_api_gateway_integration_response" "post_200" {
rest_api_id = aws_api_gateway_rest_api.api.id
resource_id = aws_api_gateway_resource.resource.id
http_method = aws_api_gateway_method.post.http_method
status_code = aws_api_gateway_method_response.post_200.status_code
selection_pattern = "-"
content_handling = "CONVERT_TO_TEXT"
response_parameters = {
"method.response.header.Access-Control-Allow-Origin" = "'*'"
}
}
resource "aws_api_gateway_deployment" "api_gateway" {
depends_on = [
aws_api_gateway_integration.post,
aws_api_gateway_integration_response.post_200,
aws_api_gateway_integration.options,
aws_api_gateway_integration_response.options_200,
]
rest_api_id = aws_api_gateway_rest_api.api.id
stage_name = "prod"
}
thats all the code
and this is the code returning error:
resource "aws_api_gateway_integration_response" "post_200" {
rest_api_id = aws_api_gateway_rest_api.api.id
resource_id = aws_api_gateway_resource.resource.id
http_method = aws_api_gateway_method.post.http_method
status_code = aws_api_gateway_method_response.post_200.status_code
selection_pattern = "-"
content_handling = "CONVERT_TO_TEXT"
response_parameters = {
"method.response.header.Access-Control-Allow-Origin" = "'*'"
}
it is returning this:
╷
│ Error: putting API Gateway Integration Response: NotFoundException: Invalid Integration identifier specified
│
│ with module.front-s3-upload.aws_api_gateway_integration_response.post_200,
│ on ../terraform/api.tf line 99, in resource "aws_api_gateway_integration_response" "post_200":
│ 99: resource "aws_api_gateway_integration_response" "post_200" {
│