Deploy, logs and delete
Four commands cover a function's life, deploy, list, logs and delete. Each takes --project, and --env when the project has more than one environment.
The commands
naijacloud functions deploy <name> --project <p> # create it, or ship a new version
naijacloud functions list --project <p> # every function, its calls and errors
naijacloud functions logs <name> --project <p> # where its logs are, and the last build log
naijacloud functions delete <name> --project <p> # remove it and its URLls and rm work as short forms of list and delete. Add --json to any of
them for output a script can read.
Deploy
naijacloud functions deploy hello --project shopRunning deploy again with the same name ships a new version to the same URL.
The URL goes to stdout and the steps go to stderr, so a script can capture it:
URL=$(naijacloud functions deploy hello --project shop)| Option | What it does |
|---|---|
--env <name> | Deploy to that environment. Without it, the project's production environment |
--file <path> | Deploy this file or folder instead of looking for one. See where the CLI looks |
--entry <file> | The entry file in a folder, when it isn't index.ts, index.js or index.mjs |
--tier <size> | The runtime's size on the first deploy: free, starter, pro or pro-max |
--json | Print the result as JSON |
When a deploy fails
If the build fails, for example on an import that can't be found, the CLI shows the reason and the last lines of the build log, and the version that was live before keeps serving:
✗ Build failed: <the reason>
This deploy failed, so the previous version (v3) is still live.
Full build log: naijacloud deployments logs <deployment-id>Fix the code and deploy again.
List
naijacloud functions list --project shopNAME STATUS CALLS 24H ERRORS 24H LAST DEPLOYED URL
hello LIVE 42 0 2 hours ago https://shop-fn.naijacloud.app/functions/v1/hello
paystack-webhook LIVE 118 1 yesterday https://shop-fn.naijacloud.app/functions/v1/paystack-webhookThe dashboard shows the same list in the Functions section of the project page.
| Status | Meaning |
|---|---|
DEPLOYING | A new version is building |
LIVE | Answering calls |
SLEEPING | A Free runtime that was idle. It wakes on the next call |
ERRORING | Live, but most recent calls fail. Check its logs |
FAILED | The newest deploy failed. An earlier version may still be serving |
STOPPED | Stopped by the platform, for example when the balance runs out |
Logs
Open the function in the dashboard and choose Logs. Each call shows its
request line (method, path, status and how long it took) above the lines your
code printed with console.log, console.warn or console.error. Lines a
function prints start with [fn:<name>. With Argus on, the same lines are in
Argus too.
From the terminal, functions logs prints the link to those live logs and the
build log of the newest version, which is where a failed deploy explains
itself:
naijacloud functions logs hello --project shop --limit 50Delete
naijacloud functions delete hello --project shopThe CLI asks you to confirm; pass --yes in a script. The function's URL stops
answering at once and its logs are removed with it. Deleting the project's last
function also removes its functions-runtime and that runtime's variables.
Environments
Functions live in one environment of a project. Without --env, every command
uses the project's production environment. Pass --env dev (or another name)
to work in another one. Each environment has its own runtime, URL and
variables.
Size: Free or paid
All the functions in one environment share one runtime. The first deploy chooses its size:
- Free, the default: it sleeps when idle and wakes on the next call, so the first call after a quiet spell takes longer. Each workspace runs functions on the Free size in one project.
- Paid (
--tier starter,proorpro-max): stays awake and allows longer calls. It is billed from your balance like a web service of the same size.
See Limits and pricing.