The dreaded This Serverless Function has crashed screen shows up for a many different reasons.
You want to avoid it, you can run a smoke test on GitHub Actions.
# The webhook event
When Vercel deploys your project, it will send a deployment_status
webhook event(opens new window) to your GitHub repository. This can be used to trigger a workflow(opens new window).
Here is the payload for the event (only including relevant fields):
{
"action": "created",
"deployment": {
"created_at": "2022-02-01T04:09:32Z",
"creator": {
"id": 35613825,
"login": "vercel[bot]",
"node_id": "MDM6Qm90MzU2MTM4MjU=",
"type": "Bot"
},
"environment": "Preview",
"original_environment": "Preview",
"production_environment": false,
"ref": "<REF>",
"sha": "<SHA>",
"task": "deploy",
"transient_environment": false,
"updated_at": "2022-02-01T04:14:20Z"
},
"deployment_status": {
"created_at": "2022-02-01T04:14:20Z",
"creator": {
"id": 35613825,
"login": "vercel[bot]",
"node_id": "MDM6Qm90MzU2MTM4MjU=",
"type": "Bot"
},
"description": "Deployment has completed",
"environment": "Preview",
"environment_url": "https://<SUBDOMAIN>.vercel.app",
"log_url": "https://<SUBDOMAIN>.vercel.app",
"repository_url": "api.github.com/repos/<OWNER>/<REPO>",
"state": "success",
"target_url": "https://<SUBDOMAIN>.vercel.app",
"updated_at": "2022-02-01T04:14:20Z",
"url": "https://api.github.com/repos/<OWNER>/<REPO>/deployments/<ID>/statuses/<STATUS_ID>"
}
}
# GitHub Actions workflow
Therefore a workflow can be created like so:
name: Vercel smoke test
on:
deployment_status: {}
jobs:
smoke:
name: Smoke test
runs-on: ubuntu-latest
if: github.event.deployment_status.state == 'success' && github.event.deployment_status.creator.login == 'vercel[bot]'
steps:
- run: |
import requests
response = requests.get('${{github.event.deployment_status.environment_url}}/api/myfunction?test=smoke')
response.raise_for_status()
print(response.status_code)
print(response.text)
shell: python
GitHub Action’s virtual environment comes with requests
module by default, so it can be used to make HTTP requests to the deployed site without having to install extra tools. The raise_for_status()
method will throw an exception if the response is not successful.