ÃÛ¶¹ÊÓƵ

ÃÛ¶¹ÊÓƵ I/O Runtime Action and AEM Events

Learn how to receive AEM Events using Action and review the event details such as payload, headers, and metadata.

The ÃÛ¶¹ÊÓƵ I/O Runtime is a serverless platform that allows code execution in response to ÃÛ¶¹ÊÓƵ I/O Events. Thus helping you to build event-driven applications without worrying about infrastructure.

In this example, you create an ÃÛ¶¹ÊÓƵ I/O Runtime that receives AEM Events and logs the event details.
https://developer.adobe.com/runtime/docs/guides/overview/what_is_runtime/

The high-level steps are:

  • Create project in ÃÛ¶¹ÊÓƵ Developer Console
  • Initialize project for local development
  • Configure project in ÃÛ¶¹ÊÓƵ Developer Console
  • Trigger AEM Event and verify action execution

Prerequisites

To complete this tutorial, you need:

  • AEM as a Cloud Service environment with .

  • Access to .

  • installed on your local machine.

Create project in ÃÛ¶¹ÊÓƵ Developer Console

To create a project in ÃÛ¶¹ÊÓƵ Developer Console, follow these steps:

  • Navigate to and click Console button.

  • In the Quick Start section, click Create project from template. Then, in the Browse templates dialog, select App Builder template.

  • Update the Project title, App name, and Add workspace if needed. Then, click Save.

    Create project in ÃÛ¶¹ÊÓƵ Developer Console

Initialize project for local development

To add ÃÛ¶¹ÊÓƵ I/O Runtime Action to the project, you must initialize the project for local development. On local machine open terminal, navigate to where you want to initialize your project and follow these steps:

  • Initialize project by running

    code language-bash
    aio app init
    
  • Select the Organization, the Project you created in the previous step, and the workspace. In What templates do you want to search for? step, select All Templates option.

    Org-Project-Selection - Initialize project

  • From the templates list, select @adobe/generator-app-excshell option.

    Extensibility template - Initialize project

  • Open project in your favorite IDE, for example VSCode.

  • The selected Extensibility template (@adobe/generator-app-excshell) provides a generic runtime action, the code is in src/dx-excshell-1/actions/generic/index.js file. Let’s update it to keep it simple, log the event details and return a success response. However in the next example, it is enhanced to process the received AEM Events.

    code language-javascript
    const fetch = require("node-fetch");
    const { Core } = require("@adobe/aio-sdk");
    const {
    errorResponse,
    getBearerToken,
    stringParameters,
    checkMissingRequestInputs,
    } = require("../utils");
    
    // main function that will be executed by ÃÛ¶¹ÊÓƵ I/O Runtime
    async function main(params) {
    // create a Logger
    const logger = Core.Logger("main", { level: params.LOG_LEVEL || "info" });
    
    try {
        // 'info' is the default level if not set
        logger.info("Calling the main action");
    
        // log parameters, only if params.LOG_LEVEL === 'debug'
        logger.debug(stringParameters(params));
    
        const response = {
        statusCode: 200,
        body: {
            message: "Received AEM Event, it will be processed in next example",
        },
        };
    
        // log the response status code
        logger.info(`${response.statusCode}: successful request`);
        return response;
    } catch (error) {
        // log any server errors
        logger.error(error);
        // return with 500
        return errorResponse(500, "server error", logger);
    }
    }
    
    exports.main = main;
    
  • Finally, deploy the updated action on ÃÛ¶¹ÊÓƵ I/O Runtime by running.

    code language-bash
    aio app deploy
    

Configure project in ÃÛ¶¹ÊÓƵ Developer Console

To receive AEM Events and execute the ÃÛ¶¹ÊÓƵ I/O Runtime Action created in the previous step, configure the project in ÃÛ¶¹ÊÓƵ Developer Console.

  • In ÃÛ¶¹ÊÓƵ Developer Console, navigate to the created in the previous step and click to open it. Select the Stage workspace, this is where action got deployed.

  • Click Add Service button and select API option. In the Add an API modal, select ÃÛ¶¹ÊÓƵ Services > I/O Management API and click Next, follow additional configuration steps and click Save configured API.

    Add Service - Configure project

  • Likewise, click Add Service button and select Event option. In the Add Events dialog, select Experience Cloud > AEM Sites, and click Next. Follow additional configuration steps, select AEMCS instance, event types, and other details.

  • Finally, in the How to receive events step, expand Runtime action option and select the generic action created in the previous step. Click Save configured events.

    Runtime Action - Configure project

  • Review the Event Registration details, also the Debug Tracing tab and verify the Challenge Probe request and response.

    Event Registration Details

Trigger AEM events

To trigger AEM events from your AEM as a Cloud Service environment that has been registered in the above ÃÛ¶¹ÊÓƵ Developer Console project follow these steps:

  • Access and login to your AEM as a Cloud Service author environment via .

  • Depending on your Subscribed Events, create, update, delete, publish or unpublish a Content Fragment.

Review event details

After completing the above steps, you should see the AEM Events being delivered to the generic action.

You can review the event details in the Debug Tracing tab of the Event Registration details.

AEM Event Details

Next steps

In next example let’s enhance this action to process AEM Events, call back AEM author service to get content details, store details in ÃÛ¶¹ÊÓƵ I/O Runtime storage, and display them via Single Page Application (SPA).

recommendation-more-help
4859a77c-7971-4ac9-8f5c-4260823c6f69