Open SwiftEngineer opened 4 years ago
Add example for creating a Lambda function that does NOT extend Scalambda
or ScalambdaIO
. A good example might be this lambda function, which handles s3 event triggers:
public class S3ObjectCreateHandler {
// The following Environment variables should be setup in Lambda
private static final String ENV_SQS_DESTINATION_IMAGES = "sqs_destination_images";
private static final String ENV_SQS_DESTINATION_VIDEOS = "sqs_destination_videos";
public Object handleRequest(S3Event input, Context context) {
JmsTemplate jmsTemplate = ... // get a jms template for publishing to SQS via JMS
for (S3EventNotificationRecord record : input.getRecords()) {
String s3Key = record.getS3().getObject().getKey();
String s3Bucket = record.getS3().getBucket().getName();
String destination = getDestinationFromKey(s3Key);
context.getLogger().log("found id: " + s3Bucket + " " + s3Key);
if (destination == null) {
context.getLogger().log("Environment variable not setup for key:" + s3Key);
} else {
jmsTemplate.convertAndSend(destination, new S3ObjectCreateMessage(s3Bucket, s3Key));
}
}
return "success";
}
private String getDestinationFromKey(String key) {
if (key.endsWith(".jpeg")) {
return System.getenv(ENV_SQS_DESTINATION_IMAGES);
} else if (key.endsWith(".mp4")) {
return System.getenv(ENV_SQS_DESTINATION_VIDEOS);
}
return null;
}
}
The goal of this would be to help folks understand that Scalambda isn't magic. At the end of the day, all it does is generate some terraform that copies your code into a Lambda function.
It'd be nice to make sure that people are able to understand that a
Scalambda
is a Lambda function class. Ideally, they should be provided some simple guide understand the limitations of this fact. For example, users should understand that aScalambda
function has all the limitations of a normal lambda function, including: