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

Java on AWS 2020-12-15

sullis
December 15, 2020

Java on AWS 2020-12-15

Portland Java User Group meetup
December 15, 2020
Portland Oregon

Topics covered:
- Amazon Corretto
- AWS CDK
- AWS SDK
- AWS Lambda
- TestContainers and LocalStack

sullis

December 15, 2020
Tweet

More Decks by sullis

Other Decks in Programming

Transcript

  1. Sean Sullivan
    Portland Java User Group
    December 15, 2020
    Java on AWS

    View Slide

  2. This presentation reflects
    my personal opinion.
    It does not represent
    the views of my employer.

    View Slide

  3. Java is fine
    2020

    View Slide

  4. View Slide

  5. which JDK should I use?

    View Slide

  6. Oracle JDK
    Amazon
    Corretto

    View Slide

  7. https://aws.amazon.com/corretto/

    View Slide

  8. Corretto
    provided at no-cost
    multi-platform
    long-term support from Amazon
    released quarterly

    View Slide

  9. Amazon runs Corretto
    internally on thousands of
    production services

    View Slide

  10. Corretto is released
    under the same
    open source license
    as OpenJDK

    View Slide

  11. https://github.com/corretto/corretto-jdk/

    View Slide

  12. Corretto is covered on the same
    basis as all other supported
    AWS Services and software.
    Already have an AWS Support Plan?

    View Slide

  13. JDK 8
    JDK 11
    JDK 15

    View Slide

  14. Corretto is multi-platform
    Linux
    Windows
    MacOS

    View Slide

  15. Corretto on Linux
    x86
    ARM

    View Slide

  16. https://twitter.com/errcraft/status/1177385675340959744
    September 2019
    Corretto on ARM64

    View Slide

  17. Corretto Docker images

    View Slide

  18. docker pull amazoncorretto:8
    docker pull amazoncorretto:15
    docker pull amazoncorretto:11

    View Slide

  19. docker manifest inspect amazoncorretto:11

    View Slide

  20. {
    "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
    "size": 742,
    "digest":
    “sha256:9e612069601762761f296c13ecb8bca198f1821ab931fa6ca7e7db6fc644ef30
    ",
    "platform": {
    "architecture": "amd64",
    "os": "linux"
    }
    }
    x86

    View Slide

  21. {
    "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
    "size": 742,
    "digest":
    “sha256:e71b5f2be284dfaa3a19cad2370600d1205fb0a41bbbe53dc530505c3ffc
    b1cb",
    "platform": {
    "architecture": "arm64",
    "os": "linux",
    "variant": "v8"
    }
    }
    ARM

    View Slide

  22. docker run amazoncorretto:11 java -version
    openjdk version "11.0.9.1" 2020-11-04 LTS
    OpenJDK Runtime Environment Corretto-11.0.9.12.1 (build 11.0.9.1+12-LTS)
    OpenJDK 64-Bit Server VM Corretto-11.0.9.12.1 (build 11.0.9.1+12-LTS, mixed mode)

    View Slide

  23. docker run amazoncorretto:11 uname -s -m
    Linux x86_64 x86

    View Slide

  24. docker run arm64v8/amazoncorretto:11 java -version
    openjdk version "11.0.9.1" 2020-11-04 LTS
    OpenJDK Runtime Environment Corretto-11.0.9.12.1 (build 11.0.9.1+12-LTS)
    OpenJDK 64-Bit Server VM Corretto-11.0.9.12.1 (build 11.0.9.1+12-LTS, mixed mode)

    View Slide

  25. docker run arm64v8/amazoncorretto:11 uname -s -m
    Linux aarch64 ARM 64

    View Slide

  26. https://aws.amazon.com/ec2/graviton/

    View Slide

  27. AWS re:Invent
    December 1, 2020

    View Slide

  28. AWS Graviton

    View Slide

  29. faster Java crypto?

    View Slide

  30. https://github.com/corretto/amazon-corretto-crypto-provider

    View Slide

  31. “algorithms are primarily
    backed by OpenSSL's
    implementations”

    View Slide

  32. Maven pom.xml

    View Slide

  33. com.amazon.corretto.crypto.provider.AmazonCorrettoCryptoProvider.install()

    View Slide

  34. Infrastructure as Code?

    View Slide

  35. Infrastructure as YAML
    Infrastructure as JSON
    Infrastructure as HCL

    View Slide

  36. AWS CDK
    https://aws.amazon.com/cdk/

    View Slide

  37. define your infrastructure
    in a familiar
    programming language

    View Slide

  38. TypeScript
    Java
    C#
    Python
    CDK languages

    View Slide

  39. writing
    YAML
    by hand
    AWS CDK

    View Slide

  40. CDK is open source

    View Slide

  41. npm install -g aws-cdk

    View Slide

  42. cdk synth
    cdk deploy
    mkdir my-project
    cd my-project
    cdk init app --language java

    View Slide

  43. View Slide

  44. Maven pom.xml

    View Slide

  45. import software.amazon.awscdk.core.Construct;
    import software.amazon.awscdk.core.Duration;
    import software.amazon.awscdk.core.Stack;
    import software.amazon.awscdk.core.StackProps;
    CDK core classes

    View Slide

  46. import software.amazon.awscdk.services.sns.Topic;
    import software.amazon.awscdk.services.sqs.Queue;
    import software.amazon.awscdk.services.lambda.Function;
    CDK Java imports

    View Slide

  47. View Slide

  48. AWS SDK for Java

    View Slide

  49. AWS SDK != AWS CDK

    View Slide

  50. AWS SDK v1
    AWS SDK v2

    View Slide


  51. software.amazon.awssdk
    dynamodb
    2.15.45

    Maven pom.xml

    View Slide

  52. import software.amazon.awssdk.regions.Region;
    import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
    import software.amazon.awssdk.services.dynamodb.model.ListTablesResponse;
    import software.amazon.awssdk.services.dynamodb.model.ListTablesRequest;
    Import statements

    View Slide

  53. View Slide

  54. Serverless Java?

    View Slide

  55. AWS Lambda

    View Slide

  56. AWS Lambda

    View Slide

  57. Maven pom.xml

    View Slide

  58. View Slide

  59. public class Handler implements RequestHandler
    public String handleRequest(S3Event s3event, Context context) {
    // handle S3 event
    }

    View Slide

  60. Lambda Powertools

    View Slide

  61. Integration Tests

    View Slide

  62. LocalStack

    View Slide

  63. https://github.com/localstack/localstack

    View Slide

  64. docker pull localstack/localstack

    View Slide

  65. LocalStack + TestContainers

    View Slide

  66. a Java library
    for embedding
    Docker containers

    View Slide

  67. Maven pom.xml

    View Slide

  68. TestContainers
    import org.testcontainers.utility.DockerImageName;
    import org.testcontainers.containers.localstack.LocalStackContainer;
    import static org.testcontainers.containers.localstack.LocalStackContainer.Service.S3;
    import static org.testcontainers.containers.localstack.LocalStackContainer.Service.SQS;

    View Slide

  69. TestContainers
    DockerImageName IMAGE_NAME = DockerImageName.parse(“localstack/localstack:0.12.3")
    public static LocalStackContainer CONTAINER = new LocalStackContainer(IMAGE_NAME)
    .withServices(S3, SQS);

    View Slide

  70. Final thoughts

    View Slide

  71. Amazon Corretto
    Java on ARM64
    Graviton2 instance types
    AWS CDK

    View Slide

  72. Questions?

    View Slide

  73. The End

    View Slide