Java, Amazon AWS Lambda and Ant

Using Java, Amazon Web Services (AWS) and Ant; a function can be created/deployed that performs the role of a scheduled task. The code can be used to make web service calls, run backup tasks, clean a database table, etc.

Source code is discussed, and a walk through goes over the process of registering the function with AWS.

All source code can be found on GitHub.

Software:

Process:

  1. Make sure all software prerequisites are downloaded/installed/configured. The user should be able to run “$ java -version” and “$ ant -version” successfully from the command line.
  2. Clone/download the source code from GitHub, and build using “$ ant”. If successful, the deployment file will be “./dist/HelloWorld.jar”.
  3. Log in to AWS, and create a new Lambda function. Click ‘Next’ to not use a blueprint. 1
  4. Configure a trigger, using a ‘CloudWatch Event – Schedule’. 2
  5. Configure the trigger to run once a minute. 3
  6. Configure the function with all of the following values. When you get to ‘Create a custom role’, you will be brought to a new screen. 4
  7. You’ll want a lambda_basic_execution role. If auto-population doesn’t work, the policy document is also in “./README.md”. 5
  8. Change the memory to ‘256’, and make the rest of the screen appear as follows. 6
  9. You will then be brought to a review page. 7
  10. After clicking ‘Create function’, you should see a confirmation page with a green bar at the top. 8
  11. Clicking on the different tabs will allow you to monitor/edit all facets of the function. 9
  12. Upon clicking on ‘View logs in CloudWatch’, you should be able to view the printout of the first successful execution. 10
  13. Code running every minute: 11

Final:
Using Java, Ant and AWS; we’ve created a scheduled task that runs Java code regularly. Lambda is used for ‘code in the cloud’, and CloudWatch events/logs are used to execute and oversee the function. The function runs once a minute, and prints information to the log.

There is much room for follow-on work including:

  • Querying a web service with the code.
  • Accessing other parts of the AWS environment, e.g RDS/DynamoDB.
  • Configuring the code to run in response to a user generated event.
  • Deploying a function with Python and/or Node.js.
  • Etc.