admin管理员组

文章数量:1126301

I have an AWS lambda built using Flask, served through API Gateway. This is deployed to AWS using Terraform. I am unable to get the favicon to load correctly when deployed through this method. The favicon works flawlessly on my local machine.

Following the advice discovered here, I am able to get the icon URL to no longer return a 502; it returns a 200. However, the icon is unable to be displayed. I can navigate directly to the icon in the browser, but I still have the same undisplayed image.

I have tried using a PNG instead of ICO, with the same results.

Of note, when I am able to see the icon locally, I see it loads with type image/x-icon, but remotely it loads as image/vnd.microsoft.icon.

My handler setup:

def handler(event, context):
    base64_content_types = ["image/vnd.microsoft.icon", "image/x-icon"]
    return awsgi.response(app, event, context, base64_content_types)

HTML link <link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">

favicon.ico is stored in the /static directory.

API specs in Terraform

resource "aws_api_gateway_rest_api" "api" {
  body = jsonencode({
    "openapi" : "3.0.1",
    "info" : {
      "title" : var.project,
      "description" : "Created by Terraform",
      "version" : "2024-11-06T18:14:04Z"
    },
    "servers" : [ {
      "url" : var.url
    } ],
    "paths" : {
      "/{proxy+}" : {
        "options" : {
          "parameters" : [ {
            "name" : "proxy",
            "in" : "path",
            "required" : true,
            "schema" : {
              "type" : "string"
            }
          } ],
          "responses" : {
            "200" : {
              "description" : "200 response",
              "content" : {
                "application/json" : {
                  "schema" : {
                    "$ref" : "#/components/schemas/Empty"
                  }
                }
              }
            }
          },
          "x-amazon-apigateway-integration" : {
            "type" : "mock",
            "responses" : {
              "default" : {
                "statusCode" : "200"
              }
            },
            "requestTemplates" : {
              "application/json" : "{\"statusCode\": 200}"
            },
            "passthroughBehavior" : "when_no_match",
            "cacheNamespace" : "q0jmk9",
            "cacheKeyParameters" : [ "method.request.path.proxy" ]
          }
        },
        "x-amazon-apigateway-any-method" : {
          "parameters" : [ {
            "name" : "proxy",
            "in" : "path",
            "required" : true,
            "schema" : {
              "type" : "string"
            }
          } ],
          "x-amazon-apigateway-integration" : {
            "type" : "aws_proxy",
            "httpMethod" : "POST",
            "uri" : aws_lambda_function.dss_lambda.invoke_arn,
            "requestParameters" : {
              "integration.request.path.proxy" : "method.request.path.proxy"
            },
            "passthroughBehavior" : "when_no_match",
            "timeoutInMillis" : 29000
          }
        }
      },
      "/" : {
        "options" : {
          "responses" : {
            "200" : {
              "description" : "200 response",
              "content" : {
                "application/json" : {
                  "schema" : {
                    "$ref" : "#/components/schemas/Empty"
                  }
                }
              }
            }
          },
          "x-amazon-apigateway-integration" : {
            "type" : "mock",
            "responses" : {
              "default" : {
                "statusCode" : "200"
              }
            },
            "requestTemplates" : {
              "application/json" : "{\"statusCode\": 200}"
            },
            "passthroughBehavior" : "when_no_templates"
          }
        },
        "x-amazon-apigateway-any-method" : {
          "x-amazon-apigateway-integration" : {
            "type" : "aws_proxy",
            "httpMethod" : "POST",
            "uri" : aws_lambda_function.dss_lambda.invoke_arn,
            "passthroughBehavior" : "when_no_match",
            "timeoutInMillis" : 29000
          }
        }
      }
    },
    "components" : {
      "schemas" : {
        "Empty" : {
          "title" : "Empty Schema",
          "type" : "object"
        }
      }
    }
  })
  name        = var.project
  binary_media_types = ["*/*"]
}

I have spent far too long googling, changing, deploying, all for a favicon. Any advice would be welcome.

本文标签: pythonFavicon not loading from Flask LambdaStack Overflow