I have an microservice running on AWS Lambda (ASP.NET Core 3.1) and published using API Gateway with custom domain.
Running locally, everything works fine, site works, images are loaded, favicon too.
Deployed to Lambda+API, site works, images are loaded (PNG, JPG), scripts are loaded, however favicon.ico is not loaded. Returns invalid image. There is no special configuration for PNG, JPG, CSS, JS or any other static content, it works out of the box.
Is there any gotcha for favicons?
The following solution worked for me.
Rather than using API Gateway to serve favicon.ico, upload it to S3 and make it a public object. Obtain the HTTPS url to this object from the S3 console. Then in your Lambda function, redirect to it.
In my case, this was an AWS Chalice (Python) application, so the routing logic was implemented as follows:
@app.route('/favicon.ico')
def favicon():
return Response(body='', headers={'Location': 'https://s3.amazonaws.com/YOUR_BUCKET_NAME/favicon.ico'}, status_code=301)
Although not strictly necessary, you can also include markup in HTML to indicate the location of the favicon, such as the following:
<link rel="icon" type="image/x-icon" href="/favicon.ico" />