Expand my Community achievements bar.

Nomination window for the Adobe Community Advisor Program, Class of 2025, is now open!
SOLVED

Best Practices for Periodic Cleanup of Old Assets and Empty Folders in AEMaaCS

Avatar

Level 7

We are working on a periodic cleanup activity in AEM as a Cloud Service (AEMaaCS) to delete assets older than 180 days. As part of this process, we also need to programmatically delete root folders if they are empty after the assets are removed. On an average, we have more than 500 assets to be cleaned up. Some questions we need clarification on:

  1. What is the recommended approach to schedule this cleanup activity in AEMaaCS?
  2. Is the Asset API still recommended for this purpose, or is it considered deprecated? If so, what alternative APIs should we use?

 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Level 8

Hi @narendiran_ravi ,

 

It's very often question what I ask myself every time when I need to manage assets in AEMaaCS. 

 

There is a official doc with all APIs: https://developer.adobe.com/experience-cloud/experience-manager-apis/ 

We have 3 options right now:

  1. Asset Manager API in SDK - deprecated
  2. Assets HTTP API - https://experienceleague.adobe.com/en/docs/experience-manager-cloud-service/content/assets/admin/mac... - good alternative
  3. Assets Author API (2024.11-experimental) - https://developer.adobe.com/experience-cloud/experience-manager-apis/api/experimental/assets/author/ . I think this API fits more for other application/consumers of AEM data.

Option #2 is a REST API to delete folders and assets.

Brief solution: Search you can implement with any search engine inside AEM, but for processing I'd suggest to start Sling Job for each asset. In this Sling job use org.apache.http.osgi.services.HttpClientBuilderFactory to create client and call HTTP REST API. Host you can configure via OSGi configuration with using ENV var.

 

This solution just came to my mind, but I will be very pleasant to hear other best practices..

 

Best regards,

Kostiantyn Diachenko.

 

View solution in original post

2 Replies

Avatar

Correct answer by
Level 8

Hi @narendiran_ravi ,

 

It's very often question what I ask myself every time when I need to manage assets in AEMaaCS. 

 

There is a official doc with all APIs: https://developer.adobe.com/experience-cloud/experience-manager-apis/ 

We have 3 options right now:

  1. Asset Manager API in SDK - deprecated
  2. Assets HTTP API - https://experienceleague.adobe.com/en/docs/experience-manager-cloud-service/content/assets/admin/mac... - good alternative
  3. Assets Author API (2024.11-experimental) - https://developer.adobe.com/experience-cloud/experience-manager-apis/api/experimental/assets/author/ . I think this API fits more for other application/consumers of AEM data.

Option #2 is a REST API to delete folders and assets.

Brief solution: Search you can implement with any search engine inside AEM, but for processing I'd suggest to start Sling Job for each asset. In this Sling job use org.apache.http.osgi.services.HttpClientBuilderFactory to create client and call HTTP REST API. Host you can configure via OSGi configuration with using ENV var.

 

This solution just came to my mind, but I will be very pleasant to hear other best practices..

 

Best regards,

Kostiantyn Diachenko.

 

Avatar

Level 9

Hi @narendiran_ravi 

 

  1. You could go with Sling Scheduled Jobs. In my opinion 500 assets are not that many, and in theory could be handled in one go, by one job. But you can also delete assets in batches, by previously running a query to detect which assets are older then you expect, and then create bucket lists of assets paths, and for each list trigger a Sling job.
    • An advantage for Sling job is that you can set a retry logic, until it manages to delete the assets.
    • A drawback is that once you trigger a job, you don't really have any nice way to control it. You at most are be able to monitor it by looking into /var/eventing/jobs. Or at least I could not find a way yet (if you know away, I would be happy to hear about it). But I guess you can also build your own simple Touch UI tool to control those jobs.

  2. You could also go with a Workflow. You can implement your own purge workflow and start it on the given assets folder. I guess you could also automate the trigger of the workflow to start periodically.
    • An advantage would be that you easily monitor and administrate workflow instances.
    • A drawback would be that you would probably need to implement custom retry logic if you want to have it.
  3. You could also create your own microservice, outside AEM, that handles this curation. Use the OOTB Assets API to interorgate AEM and send deletion commands.
    • An advantage is that you lift of the burden from AEM's shoulders and reduce load on AEM.
    • A drawback is that you need to have infrastructure to support it and also skills in the team.

 

In addition to all these, I would also think of assets references. Maybe you need to curate the content using paths to these assets as well.