Upgrade to Pro — share decks privately, control downloads, hide ads and more …

AWS SDK for Java version 2 - NYJavaSIG 2019-11-21

sullis
November 21, 2019

AWS SDK for Java version 2 - NYJavaSIG 2019-11-21

AWS SDK for Java version 2.x
NY JavaSIG
November 21, 2019

#nyjavasig
#awscloud
#awssdk
#java

sullis

November 21, 2019
Tweet

More Decks by sullis

Other Decks in Programming

Transcript

  1. Sean Sullivan
    November 21, 2019
    NY JavaSIG
    AWS SDK for Java
    version 2.x

    View full-size slide

  2. software engineer
    Portland Oregon
    Java
    Scala
    About me

    View full-size slide

  3. Agenda
    SDK for Java 2.x
    SDK internals
    Migrating from v1 to v2
    Scala and SDK v2

    View full-size slide

  4. AWS SDK for Java

    View full-size slide

  5. SDK v2
    announced
    June 2017
    @awsforjava

    View full-size slide

  6. “Under the hood, we use an
    HTTP client built on top of
    Netty to make the non-
    blocking HTTP call”
    “first class support for
    non-blocking I/O
    in our async clients”
    source: AWS Developer Blog

    View full-size slide

  7. “The AWS SDK for Java 2.0
    asynchronous client methods return
    CompletableFuture objects”
    source: SDK v2 Developer Guide

    View full-size slide

  8. import java.util.concurrent.CompletableFuture;
    DynamoDBAsyncClient client = DynamoDBAsyncClient.builder()
    .region(Region.US_WEST_2)
    .build();
    CompletableFuture response =
    client.listTables(ListTablesRequest.builder().build());
    CompletableFuture> tableNames =
    response.thenApply(ListTablesResponse::tableNames);
    tableNames.whenComplete((tables, err) -> {
    if (tables != null) {
    tables.forEach(System.out::println);
    } else {
    err.printStackTrace();
    }
    });
    SDK v2

    View full-size slide

  9. Github projects
    aws-sdk-java aws-sdk-java-v2

    View full-size slide

  10. Pull Request

    View full-size slide

  11. SDK v2
    Maven artifacts

    View full-size slide

  12. https://search.maven.org/

    View full-size slide


  13. com.amazonaws
    aws-java-sdk-dynamodb
    1.11.679

    Maven dependencies
    SDK v1

    software.amazon.awssdk
    dynamodb
    2.10.20

    SDK v2

    View full-size slide

  14. import com.amazonaws.services.cloudwatch.AmazonCloudWatchClient;
    import com.amazonaws.services.cloudwatch.AmazonCloudWatchClientBuilder;
    import com.amazonaws.services.cloudwatch.model.MetricDatum;
    import com.amazonaws.services.cloudwatch.model.PutMetricDataRequest;
    Java packages
    SDK v1
    import software.amazon.awssdk.services.cloudwatch.CloudWatchAsyncClient;
    import software.amazon.awssdk.services.cloudwatch.model.MetricDatum;
    import software.amazon.awssdk.services.cloudwatch.model.PutMetricDataRequest;
    SDK v2

    View full-size slide

  15. distinct Maven artifact names
    distinct Java package names
    SDK v2 and SDK v1
    can co-exist in a
    Java application
    SDK v1 jar
    SDK v2 jar

    View full-size slide

  16. SDK v2 programming API
    • Immutable clients and models
    • Enhanced pagination
    • Smart configuration merging
    • Forward-compatible enums
    • Streaming operations as first-class
    concepts

    View full-size slide

  17. SDK
    internals

    View full-size slide

  18. 1.7.28
    2.10.0
    4.1.42.Final
    Transitive dependencies

    View full-size slide

  19. “To provide SDK support for the many
    services that AWS owns,
    the AWS SDKs make extensive use
    of code generation”
    Code generation
    https://aws.amazon.com/blogs/developer/aws-sdk-for-java-2-x-released/

    View full-size slide

  20. Why code generation?

    View full-size slide

  21. less boilerplate
    more consistency
    Why code generation?

    View full-size slide

  22. class names
    parameter names
    method names
    exception names
    Consistency
    error handling
    logging
    JSON serialization
    network I/O

    View full-size slide

  23. AWS SDK for Java v2

    View full-size slide

  24. JavaPoet
    AWS SDK for Java v2

    View full-size slide

  25. Migrating code from v1 to v2

    View full-size slide

  26. aws-secretsmanager-caching-java

    View full-size slide

  27. https://github.com/aws/aws-secretsmanager-caching-java/

    View full-size slide

  28. “AWS Secrets Manager Java
    caching client enables
    in-process caching of secrets for
    Java applications”
    aws-secretsmanager-caching-java

    View full-size slide

  29. aws-secretsmanager-caching-java
    is based on
    AWS SDK v1

    View full-size slide

  30. https://github.com/aws/aws-secretsmanager-caching-java/issues/

    View full-size slide

  31. how to migrate
    aws-secretsmanager-
    caching-java
    from
    SDK v1 to SDK v2 ?

    View full-size slide

  32. https://github.com/
    aws/aws-
    secretsmanager-
    caching-java/pull/6

    View full-size slide

  33. https://github.com/aws/aws-secretsmanager-caching-java/pull/6/files

    View full-size slide

  34. https://github.com/aws/aws-secretsmanager-caching-java/pull/6/files

    View full-size slide

  35. Scala
    and
    AWS SDK v2

    View full-size slide

  36. val awsSdkVersion = “2.10.20”
    "org.scala-lang.modules" %% "scala-java8-compat" % “0.9.0",
    "software.amazon.awssdk" % "cloudwatch" % awsSdkVersion,
    "software.amazon.awssdk" % "dynamodb" % awsSdkVersion
    build.sbt

    View full-size slide

  37. import scala.compat.java8.FutureConverters._
    import scala.collection.JavaConverters._

    View full-size slide

  38. FutureConverters?

    View full-size slide

  39. java.util.concurrent.CompletableFuture
    scala.concurrent.Future

    View full-size slide

  40. FutureConverters.scala

    View full-size slide

  41. migrating a
    Scala library
    from
    AWS SDK v1 to v2

    View full-size slide

  42. “A tiny Scala wrapper
    around
    AWS CloudWatch Java client”
    gfc-aws-cloudwatch

    View full-size slide

  43. https://github.com/gilt/gfc-aws-cloudwatch

    View full-size slide

  44. https://github.com/
    gilt/gfc-aws-
    cloudwatch/pull/8/
    files

    View full-size slide

  45. Conclusion
    SDK v1 — production ready
    SDK v2 — production ready
    github.com/aws
    twitter.com/awsforjava

    View full-size slide

  46. Bonus material

    View full-size slide

  47. “Hands-on in the AWS Java Ecosystem”
    AWS re:Invent 2018

    View full-size slide

  48. “Developing Applications on AWS in the JVM”
    AWS re:Invent 2017

    View full-size slide

  49. https://www.slideshare.net/AmazonWebServices/
    dev205developing-applications-on-aws-in-the-jvm

    View full-size slide