Lesson 1: Bootstrap a Headless App
First, you need a new headless app created with AIO CLI. Since this app needs only a simple action to test the cron job, all other components are deselected. Follow Creating your First App Builder Application to get started.
Now go to the action code at actions/generic/index.js
to simplify what it does: make it print the current execution time to logs and return it in the result.
Copied to your clipboardconst { Core } = require('@adobe/aio-sdk')async function main (params) {const logger = Core.Logger('main', { level: 'info' })try {logger.info('Calling the main action')const currentTime = new Date()logger.info(`Current time is ${currentTime.toLocaleString()}.`)return {timeInMilliseconds: currentTime.getTime(),timeInString: currentTime.toLocaleString()}} catch (error) {logger.error(error)return { error }}}exports.main = main
Because the action is invoked only by the internal alarms, it does not need to be exposed as a web action, which would prevent access to the action by unprivileged users. Your manifest file should look like this:
Copied to your clipboardapplication:actions: actionsweb: web-srcruntimeManifest:packages:my-app:license: Apache-2.0actions:generic:function: actions/generic/index.jsweb: 'yes'runtime: 'nodejs:14'
To test the action, you could execute aio app deploy
in the VSCode terminal. Once the deployment is finished, run aio rt action invoke your-app-name/generic
, and then verify its result and logs using aio rt activation get ID
and aio rt activation logs ID
(ID
is available in the output of the invoke command earlier). This is an extract of result from the activation information: