Let’s start with a rant. I don’t like the term “Serverless” to describe Lambda or other function as a service platforms. Yeah, OK, so you don’t need to spin up servers, or worry about EC2 instances, or any of that stuff. Great. But it still runs on a server of some sort. Even nascent efforts to extend “Serverless” to edge devices still have something that could be called a server, the device itself. If it provides a service, it’s a server. It’s like that Salesforce “No Software” campaign. What? It’s freaking software, no matter what some marketing campaign says. It looks like the name is going to stick, so I’ll use it, but if you wonder why I look like I’ve just bit into a garden slug every time I say “Serverless”, that’s why.
Naming aside, there’s no doubt this is a powerful paradigm for writing, running and managing code. For one, it’s simple. It takes away all the pain of the lower levels of the stack and gives devs a superbly clean and easy environment. It is (or should be) scalable. It is (or should be) performant. The appeal is easy to see. Like most areas that AWS colonizes, Lambda seems to be the front runner in this space.
You know what else runs well in AWS? Alfresco Content and Process Services.
Lambda -> Alfresco Content / Process Services
Alfresco Content / Process Services -> Lambda
While it’s incredibly useful to be able to call Alfresco services from Lambda, what about triggering Lambda functions from the Alfresco Digital Business Platform? That part is also possible, exactly how to do it depends on what you want to do. Lambda supports many ways to invoke a function, some of which may be helpful to us.
S3 bucket events
AWS Lambda functions can be triggered in response to S3 events such as object creation or deletion. The case that AWS outlines on their web site is a situation where you might want to generate a thumbnail, which Alfresco already handles quite nicely, but it’s not hard to come up with others. We might want to do something when a node is deleted from the S3 bucket by Alfresco. For example, this could be used to trigger a notification that content cleanup was successful or to write out an additional audit entry to another system. Since most Alfresco DBP deployments in AWS use S3 as a backing store, this is an option available to most AWS Alfresco Content or Process Services instances.
Simple Email Service
Another way to trigger a Lambda function is via the AWS Simple Email Service. SES is probably more commonly used to send emails, but it can also receive them. SES can invoke your Lambda function and pass it the email it received. Sending email can already easily be done from both an Alfresco Process Services BPMN task and from an Alfresco Content Services Action, so this could be an easy way to trigger a Lambda function using existing functionality in response to a workflow event or something occurring in the content repository.
AWS CloudWatch provides a scheduled event capability for CloudWatch Events. These are configured using either a fixed rate or a cron expression, and use a rule target definition to define which Lambda function to call. A scheduled event isn’t really a way to call Lambda functions from ACS or APS, but it could prove to be very useful for regular cleanup events, archiving or other recurring tasks you wish to run against your Alfresco Content Services instances in AWS. It also gives you a way to trigger things to happen in your APS workflows on a schedule, but that case is probably better handled in the process definition itself.
Our last two options would require a little work, but may turn out to be the best for most use cases. Using an API Gateway you can define URLs that can be used to directly trigger your Lambda functions. Triggering these from Alfresco Process Services is simple, just use a REST call task to make the call. Doing so from Alfresco Content Services is a bit trickier, requiring either a custom action or a behavior that makes the call out to the API gateway and passes it the info your Lambda function needs to do its job. Still fairly straightforward, and there are lots of good examples of making HTTP calls from Alfresco Content Services extensions out there in the community.
AWS Simple Notification Service provides another scalable option for calling Lambda functions. Like the API gateway option, you could use a REST call task in Alfresco Process Services, or a bit of custom code to make the call from Alfresco Content Services. AWS SNS supports a simple API for publishing messages to a topic, which can then be used to trigger your Lambda function.
There are quite a few ways to both use Alfresco Process and Content services from Lambda functions, as well use Lambda functions to enhance your investment in Alfresco technologies. I plan to do a little spike to explore this further, stay tuned for findings and code samples!