SeaLights Java Agent - AWS Lambda Support

To collect AWS Lambda Function code coverage, we need to configure the AWS Lambda to attach Sealights java agent to the JVM startup command in the AWS Lambda Function execution environment:

 

  1. We need the AWS Lambda Layer with Sealights test listener jar. We can use the one published by Sealights or create the new one. The layer and the AWS Lambda Function need to be in the same AWS region.

    1. Use one of Sealights java AWS Lambda layers

      arn:aws:lambda:eu-west-1:442677231940:layer:sl-java-agent:1
      arn:aws:lambda:eu-west-2:442677231940:layer:sl-java-agent:1
      arn:aws:lambda:us-east-1:442677231940:layer:sl-java-agent:1
      arn:aws:lambda:us-west-2:442677231940:layer:sl-java-agent:1

    2. Create AWS Lambda Layer yourself which contains SL Test Listener java agent jar. This layer can be reused by many AWS Lambda functions.

 

  1. Configure your AWS Lambda Function to use the layer (with SL Java Agent).

During the creation of the AWS Lambda function execution environment, the layer content will be extracted into the /opt directory.

 

  1. Create or modify JAVA_TOOL_OPTIONS environment variable on AWS Lambda Function configuration page: add -javaagent parameter pointing to SL Test Listener which is placed in /opt directory.

    1. JAVA_TOOL_OPTIONS environment variable value can also contain sl properties that we need to pass to the agent, for example:

      -javaagent:/opt/sl-test-listener.jar -Dsl.buildSessionIdFile=/var/task/buildSessionId.txt -Dsl.enableUpgrade=false -Dsl.tags=aws-lambda -Dsl.collectorUrl=http://mycollector.dns
    2. You can set other environment variables - that will be picked up automatically by the agent - like SL_TOKEN, SL_BUILDSESSIONID, SL_LAB_ID & SL_COLLECTOR_URL (whose names match the SL properties by replacing “." in the SL property name with "_").

 

  1. For each version of the function code update, you’re required to update buildSessionId configuration on AWS Lambda Function environment:

    1. Scan the function code outside the AWS Lambda environment with the Sealights Java build Scanner (or maven/gradle plugin). The buildSessionId will be generated and its bytecode metadata (code changes) will be sent to Sealights Cloud Services.

    2. Deploy function code and update buildSessionId in AWS Lambda function configuration.

      1. If you pack your function code together with buildSessionId.txt and sltoken.txt and deploy it then buildSessionId.txt and sltoken.txt will be available in /var/task in AWS Lambda function execution environment (as the AWS Lambda function jar’s content is extracted into /var/task directory)

      2. you can pass buildSessionId to Sealights Java Agent by setting the environment variable SL_BUILDSESSIONID

    3. You can now execute your tests: The Sealights Test listener will be attached to JVM on the AWS Lambda Function execution environment to collect coverage information and send it to the Sealights Cloud Platform.