Skip to content

Commit

Permalink
Merge pull request #31 from blackboard/feature/serverless-framework-d…
Browse files Browse the repository at this point in the history
…eploy

Automated Deployment of Java lambda-selenium Demo
  • Loading branch information
tsu-denim authored May 16, 2018
2 parents 4d51ce3 + 809487c commit 768949a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 36 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ build/

# Gradle #
.gradle/

# Serverless #
.serverless/
50 changes: 15 additions & 35 deletions docs/java-tutorial.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,35 @@
# Lambda-Selenium: Java Tutorial [![Build Status](https://travis-ci.org/blackboard/lambda-selenium.svg?branch=master)](https://travis-ci.org/blackboard/lambda-selenium)

#### Running The Example
* [Download the latest release - java_lambda_function.zip](https://github.com/blackboard/lambda-selenium/releases/latest)
* Upload the release zip into an s3 bucket and copy the link for the file.
* Create a new Lambda Function in AWS with the following name

```shell
lambda-selenium-function
```
_Note: for the tests to execute this name is required_

**_Change the settings of the Lambda Function_**
1. Set the Runtime to Java 8
2. Set the Handler to com.blackboard.testing.lambda.LambdaTestHandler::handleRequest
3. Set the Memory to 1536 MB
4. Set the Timeout to 5 min
5. Set the Code entry type to Upload a file from Amazon S3
6. Paste in the location of the package previously uploaded into the S3 link URL
7. Save the changes

Note: S3 is required because of the size of the package.

Now the function is ready to be invoked.

**_Use shell commands to clone the repository and change the working directory to the Java example_**
```shell
git clone [email protected]:blackboard/lambda-selenium.git
cd lambda-selenium/lambda-selenium-java/
```

**_Next, run the test suite 'ExampleTestSuite' inside the same shell :_**
```shell
gradle clean test
```

When the tests are ran, they will be executed in parallel by invoking the Lambda function that was created.
Once the tests are complete, open folder './build/screenshots' to view screenshots taken inside the running tests.
If a test fails, the exception will be thrown for the test case and logged to the console.


#### Packaging A New Function

**_To package the jar, run the following command inside the lambda-selenium-java directory_**
**_To package the jar and deploy it, run the following command inside the lambda-selenium-java directory_**
```shell
gradle clean unzipLibs shadowJar
gradle clean unzipLibs shadowJar deploy
```

This will package all of the required dependencies and code within the jar file.
The libraries that we included in the resources folder will also be included in this jar.
Once the jar has been built, you can find it in the build/libs folder.
This jar can then be deployed in a new lambda function.
This jar will then be deployed as a new lambda function using the [serverless framework](https://serverless.com/).

Note: If you change the name to a different lambda function, you must change the name of the
Note: If you change the name to a different lambda function in the [serverless.yml](../lambda-selenium-java/serverless.yml), you must change the name of the
function that is invoked in the code in the class com.blackboard.testing.lambda.LambdaSeleniumService

Now the function is ready to be invoked.

**_Next, run the test suite 'ExampleTestSuite' inside the same shell :_**
```shell
gradle clean test
```

When the tests are ran, they will be executed in parallel by invoking the Lambda function that was created.
Once the tests are complete, open folder './build/screenshots' to view screenshots taken inside the running tests.
If a test fails, the exception will be thrown for the test case and logged to the console.
2 changes: 1 addition & 1 deletion lambda-selenium-java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ shadowJar {
}

task deploy(type: Exec) {
commandLine 'sh', './build-deploy.sh'
commandLine 'sls', 'deploy'
}
19 changes: 19 additions & 0 deletions lambda-selenium-java/serverless.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# serverless.yml
service: lambda-selenium

package:
artifact: build/libs/lambda-selenium-all.jar

provider:
name: aws
stage: ${opt:stage, 'dev'}
runtime: java8
memorySize: 3008
timeout: 300
versionFunctions: false

functions:
'lambda-selenium-demo':
handler: 'com.blackboard.testing.lambda.LambdaTestHandler::handleRequest'
name: lambda-selenium-function
description: Lambda Selenium Demo Tests

0 comments on commit 768949a

Please sign in to comment.