Using AEM events in Adobe IO – AEMaaCS

In certain scenarios, you may need to perform extensive processing in response to events occurring within AEM. Nowadays, Adobe I/O presents a contemporary solution in such situations to offload processing from AEM.

For example, say you need to invalidate Akamai cache upon page replication. In this scenario, you can capture the page publish event in Adobe I/O and trigger the invalidate call to Akamai through Adobe I/O using a runtime function. Alternatively, you could set up a webhook on Adobe I/O to make the API call directly from the webhook.

In such situations, the first step is to enable Adobe I/O events. To simplify this process, I’ve compiled the steps below.

1) Embedding and installing aio-aem-events package in AEM
aio-aem-events
is a addon module which facilitates integration of AEM events with Adobe IO

To achieve this, navigate to the pom.xml file located in the ‘all’ directory, and include aio-aem-events in the dependencies section.

<dependency>
    <groupId>com.adobe.aio.aem</groupId>
    <artifactId>aio-aem-events</artifactId>
    <version>${aio-aem-events.version}</version>
    <type>zip</type>
</dependency>

Include aio-aem-events as Embedded/Sub packages within the configuration section of the filevault-package-maven-plugin in all pom.

<embedded>
     <groupId>com.adobe.aio.aem</groupId>
     <artifactId>aio-aem-events</artifactId>
     <type>zip</type>
     <target>/apps/mysite-packages/application/install</target>
</embedded>

2) Generate the public private key pair
To generate the key pair follow the instructions provided in the link. The base64-encoded public key will be utilised later for configuring WorkspaceSupplierImpl.

3) Create a project in Adobe IO
Select a project with a template, specifically an app builder template. Next, add an API by navigating to “IO Management API” and then selecting “JWT”. You can either generate and download the configuration zip file or choose the 2nd option and upload the generated public key in step2 (I followed the latter option).

Please note as of today, we must utilise deprecated JWT authentication as OAuth is not supported by legacy IO events.

Download the workspace JSON and keep it handy. It will be needed later for configuring the WorkspaceSupplierImpl OSGi config.

4) Configure the WorkspaceSupplierImpl OSGI Config 
Within your ui.config module, create an OSGi configuration file for PID com.adobe.aio.aem.workspace.internal.WorkspaceSupplierImpl.cfg.json.

Your OSGI configuration could look like this:

{
    "aio.consumer.org.id": "$[env:aio_consumer_org_id]",
    "aio.ims.org.id": "$[env:aio_ims_org_id]",
    "aio.meta.scopes": "$[env:aio_meta_scopes]",
    "aio.project.id": "$[env:aio_project_id]",
    "aio.workspace.id": "$[env:aio_workspace_id]",
    "aio.api.key": "$[env:aio_api_key]",
    "aio.credential.id": "$[env:aio_credential_id]",
    "aio.technical.account.id": "$[env:aio_technical_account_id]",
    "aio.client.secret": "$[secret:aio_client_secret]",
    "aio.encoded.pkcs8": "$[secret:aio_encoded_pkcs8]"
}

Utilise your base 64 public key and workspace.json to populate these values. On AEM Cloud, ensure these values are stored in Cloud manager environment variables.

5) Deploy to AEM and run health checks.
Deploy your code to AEM. Ensure that the AIO bundle is active in the AEM, and verify that the workspace OSGi configuration and events are visible in the system console.

6) Run the health checks
To confirm our WorkspaceSupplierImpl configuration is correct run the health checks. If all the health checks pass the AEM provider is properly configured to emit events to Adobe IO.

7) View the provider & events in Adobe IO
If health checks are success you should be able to see the events and event provider AEM in adobe IO. You can now configure the event registration to act upon the event.

Note that adding events is not mandatory at this moment; it can be done after deploying your runtime action.

Further Reading:

Frequently Encountered Issues with Adobe IO Events

References:
https://developer.adobe.com/events/docs/guides/using/aem/aem-addon-module/aem_skyline_install/

1 Comment

  1. Arun Gopalan Muralidhara

    Nice Article to start with the setup

Leave a Reply

Your email address will not be published. Required fields are marked *