AWS SDK for Java 2.0

repository·master·Indexed 25 days ago

https://github.com/aws/aws-sdk-java-v2

A complete rewrite of the Java SDK designed for improved performance via non-blocking IO and pluggable HTTP implementations. It includes Maven archetypes for quickstarting client applications (archetype-app-quickstart) and Lambda functions (archetype-lambda), support for GraalVM Native Image, and an alternate syntax for event streaming APIs to simplify bi-directional communication over HTTP/2.

Tokens
69.8K
Snippets
109
Records
237
Agent score
77%

What's inside aws-sdk-java-v2

  1. Understand SDK Metrics module structure

    master

    The SDK metrics system is split into two primary modules:

    1. metrics-spi: Contains metrics interfaces and default implementations. This is a sub-module of core. Because sdk-core depends on metrics-spi, it is included automatically in your project.
    2. metrics-publishers: Contains implementations of all supported publishers. This module contains sub-modules for each specific publisher (e.g., cloudwatch-publisher, csm-publisher). You must add these dependencies manually to use them.
  2. Use the DynamoDB Enhanced Client for idiomatic Java development

    master

    The DynamoDB Enhanced Client is a high-level library designed to provide a more idiomatic Java experience compared to the standard DynamoDbClient. It simplifies data access by handling conversions between Java objects (POJOs) and DynamoDB items, supporting common Java data types (like Instant or Number) that the standard client requires manual conversion for.

    Key capabilities include:

    • Object Mapping: Automatic conversion between Java objects and DynamoDB items.
    • Data-Plane Operations: Direct support for all DynamoDB data-plane operations using the same verbs and nouns as the service.
    • Testing Support: Ability to create tables using the same models used for data-plane operations.
    • Reduced Boilerplate: Eliminates the need to manually convert types or map objects to item representations.

    Note: This client is a 'Level 2' library, meaning it is service-specific and built on top of the generated DynamoDbClient. For full implementation details and usage, refer to the DynamoDb Enhanced Public Preview Library.

  3. Use S3TransferManager for high-level S3 object transfers

    master

    The S3TransferManager is a high-level, asynchronous, and non-blocking library built on top of the standard S3 client. It is designed to be the preferred solution for uploading and downloading S3 objects because it is more intuitive and generally more performant than using the low-level S3 client directly.

    Key features include:

    • Asynchronous API: Conforms to SDK norms for non-blocking operations.
    • Parallelism: Supports parallel downloads of any object (not just those uploaded via Multipart API).
    • Resource Efficiency: Designed to make efficient use of system resources.
    • Advanced Transfer Capabilities:
      • Bandwidth limiting for uploads and downloads.
      • Support for uploads/downloads to and from memory.
      • Support for uploading to and downloading from pre-signed URLs.
      • Support for progress listeners.
      • Support for canned ACL policies.
      • Trailing checksums for parallel transfers.
  4. Use the {Service}BatchManager utility

    master
    The SDK provides a batching utility named {Service}BatchManager (e.g., SQSBatchManager) to facilitate batch operations on low-level service clients. This utility is separate from the standard service client and operates similarly to TransferManager. It is designed to handle batching logic, including manual flushing and buffer management, without replacing the core client methods.
  5. Design Overview: v2 Transfer Manager Progress Listeners

    master

    The AWS SDK for Java v2 is introducing a new progress listener mechanism for TransferManager-initiated uploads and downloads. This feature aims to provide an intuitive way to track transfer progress (e.g., for displaying progress bars) without the confusing overloaded parameters found in the Java SDK v1 ProgressListener.

    Key goals for this implementation include:

    • Creating an intuitive interface for tracking upload/download progress.
    • Facilitating common progress bar logic.
    • Designing for reuse across different use cases beyond TransferManager.
    • Ensuring extensibility and minimal performance impact.
    • Avoiding unnecessary overlap with the existing ExecutionInterceptor system.
  6. Understand the AWS SDK for Java v2 versioning scheme

    master

    The SDK uses a MAJOR.MINOR.PATCH[-QUALIFIER] versioning format. Unlike strict semantic versioning, PATCH releases may include new features. Use the version components to assess upgrade risk:

    • MAJOR: High risk. Expect API incompatibilities and breaking changes.
    • MINOR: Medium risk. Upgrading should generally work, but check release notes. Changes may include incrementing minimum Java versions, deprecating APIs, or significant core runtime changes.
    • PATCH: Low risk. Contains bug fixes and new features.
    • QUALIFIER: Optional (e.g., PREVIEW).
  7. Understand Request Presigners

    master

    Request presigning allows a signature creator to use their secret signing credentials to generate an AWS request. This presigned request can then be executed by a separate signature user within a fixed time period without requiring additional authentication.

    There is a distinction between a presigned request and a presigned URL:

    1. Presigned Request: Any request signed using query parameter signing intended for another entity to execute later. This may require the user to provide specific headers and payloads.
    2. Presigned URL: A specific type of presigned request that is easily executable by a browser. To qualify as a presigned URL, the request must:
      • Use the GET HTTP method.
      • Not include a payload.
      • Not include content-type or x-amz-* headers.

    For example, an S3 GetObjectRequest is only a presigned URL if it excludes specific headers like x-amz-server-side-encryption-customer-algorithm, x-amz-server-side-encryption-customer-key, x-amz-server-side-encryption-customer-key-MD5, or x-amz-request-payer. Including these would cause a signature mismatch in a browser because the browser would not send those headers.

  8. Presign S3 operations using S3Presigner

    master

    To generate presigned URLs for S3 operations (like GetObject or PutObject), use the {Service}Presigner pattern. The SDK provides specific request and response shapes for each operation to ensure type safety and ease of use. You can use either a builder pattern or a lambda-based Consumer approach to configure the presign request.

    // Using the Builder pattern
    s3.presignGetObject(GetObjectPresignRequest.builder()
                                               .getObject(GetObjectRequest.builder().bucket("bucket").key("key").build())
                                               .signatureDuration(Duration.ofMinutes(15))
                                               .build());
    
    // Using the Consumer pattern
    s3.presignGetObject(r -> r.signatureDuration(Duration.ofMinutes(15))
                              .getObject(go -> go.bucket("bucket").key("key")));