Versioning

Versioning was the first feature added to Lambda once its inception. Here's how it works:

  • You call the CreateFunctionCode call, which registers a function named lb_handleSns with two Amazon Resource Names (ARNs), like:
    • arn:aws:lambda:us-east-1:235368163414:function:lb_handleSns and
    • arn:aws:lambda:us-east-1:235368163414:function:lb_handleSns:$LATEST
  • When you call the invoke method of Lambda, you can either specify its function name (lb_handleSns) or the full ARN to the function (using the examples above, both will refer to the latest version of the version)
  • However, when you call the UpdateFunctionCode on an existing function with the publish attribute set to true, the old $LATEST version will be renamed to arn:aws:lambda:us-east-1:235368163414:function:lb_handleSns:1, thus allowing you to invoke the previous version

For more details, here is the AWS Reference on Versioning.

Using Versions and Aliases on Lambada

Lets look at the sns-example project for now. It declares an alias:

It defines an alias:

public class SNSEventHandler {
  @LambadaFunction(name="lb_handleSns", alias="lb_handleSns_latest", description="Handle SNS Events")
  public void handleSNSEvent(SNSEvent snsEvent) throws Exception {
    System.out.println("snsEvent: " + snsEvent);
  }
}

For now, just deploy the first version (with verbose logging, so we can track its API calls):

$ mvn -f sns-example/pom.xml -Pdeploy deploy -Dbeanstalker.verbose=true
...
[INFO] Merged into 1 definitions:
[INFO] Deploying Function: lb_handleSns (handler: io.ingenieux.lambada.SNSEventHandler::handleSNSEvent)
[INFO] Function does not exist. Creating it instead.
[INFO] SUCCESS
[INFO] {
[INFO]   "lb_handleSns" : {
[INFO]     "name" : "lb_handleSns",
[INFO]     "alias" : "lb_handleSns_latest",
[INFO]     "description" : "Handle SNS Events",
[INFO]     "memorySize" : 128,
[INFO]     "role" : "arn:aws:iam::235368163414:role/lambda_basic_execution",
[INFO]     "timeout" : 5,
[INFO]     "handler" : "io.ingenieux.lambada.SNSEventHandler::handleSNSEvent"
[INFO]   }
[INFO] }
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

If you look at the console, there'll be no mention of version nor aliases declared:

Where is it?

Here's what happens: The Lambda Maven Plugin for Beanstalker doesn't have versioning (including Aliases) turned on by default:

  /**
   * Publish a new function version?
   */
  @Parameter(property = "lambda.deploy.publish", defaultValue = "false")
  Boolean deployPublish;

  /**
   * Publish a new function version?
   */
  @Parameter(property = "lambda.deploy.aliases", defaultValue = "false")
  Boolean deployAliases;

So, If you run declaring lambda.deploy.publish, versions will be made. Say, overriding via commandline:

$ mvn -f sns-example/pom.xml -Pdeploy -Dlambda.deploy.publish=true

The same also applies to aliases:

$ mvn -f sns-example/pom.xml -Pdeploy -Dlambda.deploy.publish=true -Dlambda.deploy.aliases=true

Here's the result:

Now there are aliases set!

Alternate Views on Versioning

We also support a property-based take on names. Replace the annotation on the example above from:

  @LambadaFunction(name="lb_handleSns", alias="lb_handleSns_latest", description="Handle SNS Events")
  public void handleSNSEvent(SNSEvent snsEvent) throws Exception {

To:

  @LambadaFunction(name="lb_handleSns", alias="lb_handleSns_${environmentName}", description="Handle SNS Events")
  public void handleSNSEvent(SNSEvent snsEvent) throws Exception {

These values will be interpolated by lambda-maven-plugin AND written back to disk. For instance, run lambada:generate and example the contents of target/META-INF/lambda-definitions.json:

$ mvn -f sns-example/pom.xml -Pdeploy clean compile lambada:generate -DenvironmentName=dev

Then lambda-definitions.json will be:

[ {
  "name" : "lb_handleSns",
  "alias" : "lb_handleSns_${environmentName}",
  "description" : "Handle SNS Events",
  "handler" : "io.ingenieux.lambada.SNSEventHandler::handleSNSEvent"
} ]

Now, run this:

$ mvn -f sns-example/pom.xml -Pdeploy clean deploy -DenvironmentName=dev

The contents of lambda-definitions.json will be:

[ {
  "name" : "lb_handleSns",
  "alias" : "lb_handleSns_dev",
  "description" : "Handle SNS Events",
  "memorySize" : 128,
  "role" : "arn:aws:iam::235368163414:role/lambda_basic_execution",
  "timeout" : 5,
  "handler" : "io.ingenieux.lambada.SNSEventHandler::handleSNSEvent",
  "api" : null
} ]