Skip to content

Notes and examples for the Sydney Java Meetup's Lambda Workshop

License

Notifications You must be signed in to change notification settings

SydneyJavaMeetup/JavaLambdaWorkshop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 

Repository files navigation

Java Lambda Workshop

Notes and examples for the Sydney Java Meetup's Lambda Workshop

Workshop Outline

Prerequisites

PART 1

Project Instantiation

  • Initialize SAM CLI Java project
    sam init -r java8 -n starry-skies
    
  • Run
    cd starry-skies
    mvn clean test    
  • Open in IntelliJ for some IDE goodness
    idea .
  • Remember to fix the module Java versions if IntelliJ didn't pick them up
  • Build the package
    mvn package

At this point we should have an uber-jar in starry-skies/target/HelloWorld-1.0.jar.

Running locally

Debugging it locally

  • Add a 'remote' debug configuration in IntelliJ / equivalent Eclipse

  • Put a breakpoint in App::handler

  • Run the service:

    sam local start-api -d 9292
  • Start a browser:

    http://127.0.0.1:3000/hello

    (the local lambda will pause waiting for you to attach a debugger)

BREAK

Take a break for questions and getting everyone up to the same place.

PART 2

A Little Style

Let's upgrade the default SAM CLI implementation with some generics and stronger typing.

Functionality

Let's make our function do something fun!

BREAK

PART 3

Cloud Deployment

Let's deploy our functions to AWS cloud and invoke them from the browser.

Cloud Monitoring

Let's add some metrics to our function and show them on a dashboard.

private void writeMetric(String name, double value) {
    try {
        final AmazonCloudWatch cw =
                AmazonCloudWatchClientBuilder.defaultClient();

        MetricDatum datum = new MetricDatum()
                .withMetricName(name)
                .withUnit(StandardUnit.Milliseconds)
                .withValue(value);

        PutMetricDataRequest request = new PutMetricDataRequest()
                .withNamespace("VISUALISING_PERFORMANCE")
                .withMetricData(datum);

        PutMetricDataResult putMetricDataResult = cw.putMetricData(request);
        System.out.println(putMetricDataResult.getSdkResponseMetadata());

    } catch (Exception e) {
        System.out.println("Failed to write CloudWatch metric." + e.getMessage());
        e.printStackTrace();
    }
}

About

Notes and examples for the Sydney Java Meetup's Lambda Workshop

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published