This template customizes the response for unauthorized requests in an AWS API Gateway REST API.

Terraform Template

resource "aws_api_gateway_gateway_response" "test" {

  response_parameters = {
    gatewayresponse.header.Authorization = "'Basic'"
    gatewayresponse = "[object Object]"
  }

  response_templates = {
    application/json = "{"message":$context.error.messageString}"
  }
  response_type = "UNAUTHORIZED"
  rest_api_id = aws_api_gateway_rest_api.main.id
  status_code = "401"
}

resource "aws_api_gateway_rest_api" "main" {
  name = "MyDemoAPI"
}