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

Java on AWS 2020-12-15

99d4c0ed3c8027ea1c37b53d6441d042?s=47 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 Lambda
- TestContainers and LocalStack



December 15, 2020

More Decks by sullis

Other Decks in Programming


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

    on AWS
  2. This presentation reflects my personal opinion. It does not represent

    the views of my employer.
  3. Java is fine 2020

  4. None
  5. which JDK should I use?

  6. Oracle JDK Amazon Corretto

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

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

  9. Amazon runs Corretto internally on thousands of production services

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

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

  12. Corretto is covered on the same basis as all other

    supported AWS Services and software. Already have an AWS Support Plan?
  13. JDK 8 JDK 11 JDK 15

  14. Corretto is multi-platform Linux Windows MacOS

  15. Corretto on Linux x86 ARM

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

  17. Corretto Docker images

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

  19. docker manifest inspect amazoncorretto:11

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

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

    "architecture": "arm64", "os": "linux", "variant": "v8" } } ARM
  22. docker run amazoncorretto:11 java -version openjdk version "" 2020-11-04 LTS

    OpenJDK Runtime Environment Corretto- (build OpenJDK 64-Bit Server VM Corretto- (build, mixed mode)
  23. docker run amazoncorretto:11 uname -s -m Linux x86_64 x86

  24. docker run arm64v8/amazoncorretto:11 java -version openjdk version "" 2020-11-04 LTS

    OpenJDK Runtime Environment Corretto- (build OpenJDK 64-Bit Server VM Corretto- (build, mixed mode)
  25. docker run arm64v8/amazoncorretto:11 uname -s -m Linux aarch64 ARM 64

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

  27. AWS re:Invent December 1, 2020

  28. AWS Graviton

  29. faster Java crypto?

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

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

  32. Maven pom.xml

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

  34. Infrastructure as Code?

  35. Infrastructure as YAML Infrastructure as JSON Infrastructure as HCL

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

  37. define your infrastructure in a familiar programming language

  38. TypeScript Java C# Python CDK languages

  39. writing YAML by hand AWS CDK

  40. CDK is open source

  41. npm install -g aws-cdk

  42. cdk synth cdk deploy mkdir my-project cd my-project cdk init

    app --language java
  43. None
  44. Maven pom.xml

  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

  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

  47. None
  48. AWS SDK for Java

  49. AWS SDK != AWS CDK

  50. AWS SDK v1 AWS SDK v2

  51. <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>dynamodb</artifactId> <version>2.15.45</version> </dependency> Maven pom.xml

  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

  53. None
  54. Serverless Java?

  55. AWS Lambda

  56. AWS Lambda

  57. Maven pom.xml

  58. None
  59. public class Handler implements RequestHandler<S3Event, String> public String handleRequest(S3Event s3event,

    Context context) { // handle S3 event }
  60. Lambda Powertools

  61. Integration Tests

  62. LocalStack

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

  64. docker pull localstack/localstack

  65. LocalStack + TestContainers

  66. a Java library for embedding Docker containers

  67. Maven pom.xml

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

  69. TestContainers DockerImageName IMAGE_NAME = DockerImageName.parse(“localstack/localstack:0.12.3") public static LocalStackContainer CONTAINER =

    new LocalStackContainer(IMAGE_NAME) .withServices(S3, SQS);
  70. Final thoughts

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

  72. Questions?

  73. The End