Community程式設計與開發github.com

giuseppe-trisciuoglio/aws-sdk-java-v2-core

提供 AWS SDK for Java 2.x 的用戶端設定、憑證解析、HTTP 用戶端調校、超時、重試與測試模式。適用於建立或強化 AWS 服務用戶端、配置 Spring Boot Bean、除錯驗證或區域問題,或選擇同步與非同步 SDK 使用方式。

aws-sdk-java-v2-core 是什麼?

此技能專注於 AWS SDK for Java 2.x 的核心設定與最佳實踐,協助開發者有效建立、配置和測試 AWS 服務用戶端。它涵蓋了憑證解析(如使用 DefaultCredentialsProvider 或 ProfileCredentialsProvider)、HTTP 用戶端調校(如連線池大小、超時設定、DNS 解析與 SSL/TLS 配置)、重試策略(如 RetryPolicy 與重試模式),以及同步與非同步 SDK 的選擇。此技能也詳細說明如何在 Spring Boot 環境中注入 AWS 用戶端為 Bean,並提供單元測試(使用 AWS SDK 的測試工具)與整合測試的建議。支援所有使用 AWS SDK for Java 2.x 的平台(如 EC2、ECS、Lambda、本機開發環境),透過遵循其提供的模式,可避免常見的連線逾時、認證失敗、節流等問題。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/giuseppe-trisciuoglio/developer-kit/tree/main/skills/aws-sdk-java-v2-core

Installed? Explore more 程式設計與開發 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

aws-sdk-java-v2-core 是做什麼的?

提供 AWS SDK for Java 2.x 的用戶端設定、憑證解析、HTTP 用戶端調校、超時、重試與測試模式。適用於建立或強化 AWS 服務用戶端、配置 Spring Boot Bean、除錯驗證或區域問題,或選擇同步與非同步 SDK 使用方式。

總覽

此技能涵蓋以下核心領域:

  • 用戶端建立:使用 SdkClientBuilder 和 SdkDefaultClientBuilder 建立服務用戶端。
  • 憑證解析:設定 CredentialsProvider 鏈(env、system 屬性、profile、ECS/EC2 中繼資料)。
  • 區域解析:設定 Region(使用 Region.of() 或 DefaultRegionProvider)。
  • HTTP 用戶端調校:選擇 Apache 或 Netty HTTP 用戶端,並調校連線、超時、閒置連線管理等。
  • 重試與逾時:設定 RetryPolicy(自訂退避、節流重試)與 ApiCallTimeout。
  • 同步 vs 非同步:選擇 SyncClient 或 AsyncClient 的考量與實作細節。
  • Spring Boot 整合:將 AWS 用戶端注入為 @Bean 並使用 @ConfigurationProperties。
  • 測試:使用 Mockito 模擬用戶端、使用 WireMock 模擬 HTTP 端點、使用 AmazonS3Client 的本機測試模式。

使用方式

建立 S3 用戶端(同步)

S3Client s3 = S3Client.builder()
    .region(Region.of("us-west-2"))
    .credentialsProvider(DefaultCredentialsProvider.create())
    .httpClient(ApacheHttpClient.builder()
        .maxConnections(50)
        .socketTimeout(Duration.ofSeconds(10))
        .build())
    .overrideConfiguration(b -> b
        .retryPolicy(RetryPolicy.builder()
            .numRetries(3)
            .backoffStrategy(ExponentialBackoffRetryStrategy.builder()
                .baseDelay(Duration.ofMillis(200))
                .maxBackoffTime(Duration.ofSeconds(20))
                .build())
            .build())
        .apiCallTimeout(Duration.ofSeconds(30)))
    .build();

使用 Spring Boot 配置

@Configuration
public class AwsConfig {

    @Bean
    public S3Client s3Client(
            @Value("${aws.region:us-east-1}") String region,
            @Value("${aws.s3.endpoint-override:#{null}}") String endpointOverride) {
        var builder = S3Client.builder()
                .region(Region.of(region))
                .credentialsProvider(DefaultCredentialsProvider.create());
        if (endpointOverride != null && !endpointOverride.isEmpty()) {
            builder.endpointOverride(URI.create(endpointOverride));
        }
        return builder.build();
    }
}

設定 application.yml

aws:
  region: eu-west-1
  s3:
    endpoint-override: http://localhost:4566

常見問題與解決方案

問題解決方案
CredentialsProviderException確認 AWS 憑證已透過環境變數 (AWS_ACCESS_KEY_ID、AWS_SECRET_ACCESS_KEY) 或 IAM 角色設定。
SocketTimeoutException增加 socketTimeout(預設 10 秒)或 apiCallTimeout(預設 30 秒)。
請求限制 (Throttling)啟用重試並使用指數退避策略。
區域不符明確設定 Region 或在環境變數 AWS_REGION 中指定。
非同步用戶端記憶體不足使用 EventLoopGroup 並限制並行請求數(使用 Semaphore)。

最佳實踐

  • 重複使用用戶端:將 AWS 用戶端建立為單例或 Spring Bean,避免重複建立。
  • 設定明確的超時:總是設定 socketTimeout 與 apiCallTimeout。
  • 選擇適當的 HTTP 用戶端:同步使用 ApacheHttpClient,非同步使用 NettyNioAsyncHttpClient(或 AwsCrtAsyncHttpClient 以獲得最佳效能)。
  • 使用非同步編程:對於高吞吐量或連線數多的場景,選擇非同步用戶端。
  • 記錄與監控:啟用 SDK 層級記錄(設定 software.amazon.awssdk 的日誌級別為 DEBUG)。

支援的平台

  • AWS Lambda(Java 執行環境)
  • Amazon ECS / Fargate(使用 ECS 中繼資料端點取得憑證)
  • Amazon EC2(使用 IMDS)
  • 本機開發(透過環境變數或 ~/.aws/credentials 設定檔)
  • Spring Boot 應用程式

參考資料

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

giuseppe-trisciuoglio/aws-lambda-java-integration

Provides AWS Lambda integration patterns for Java with cold start optimization. Use when deploying Java functions to AWS Lambda, choosing between Micronaut and Raw Java approaches, optimizing cold starts below 1 second, configuring API Gateway or ALB integration, or implementing serverless Java applications. Triggers include "create lambda java", "deploy java lambda", "micronaut lambda aws", "java lambda cold start", "aws lambda java performance", "java serverless framework".

giuseppe-trisciuoglio/aws-lambda-php-integration

Provides AWS Lambda integration patterns for PHP with Symfony using the Bref framework. Creates Lambda handler classes, configures runtime layers, sets up SQS/SNS event triggers, implements warm-up strategies, and optimizes cold starts. Use when deploying PHP/Symfony applications to AWS Lambda, configuring API Gateway integration, implementing serverless PHP applications, or optimizing Lambda performance with Bref. Triggers include "create lambda php", "deploy symfony lambda", "bref lambda aws", "php lambda cold start", "aws lambda php performance", "symfony serverless", "php serverless framework".

giuseppe-trisciuoglio/aws-lambda-python-integration

Provides AWS Lambda integration patterns for Python with cold start optimization. Use when deploying Python functions to AWS Lambda, choosing between AWS Chalice and raw Python approaches, optimizing cold starts, configuring API Gateway or ALB integration, or implementing serverless Python applications. Triggers include "create lambda python", "deploy python lambda", "chalice lambda aws", "python lambda cold start", "aws lambda python performance", "python serverless framework".

giuseppe-trisciuoglio/aws-lambda-typescript-integration

Provides AWS Lambda integration patterns for TypeScript with cold start optimization. Use when creating or deploying TypeScript Lambda functions, choosing between NestJS framework and raw TypeScript approaches, optimizing cold starts, configuring API Gateway or ALB integration, or implementing serverless TypeScript applications. Triggers include "create lambda typescript", "deploy typescript lambda", "nestjs lambda aws", "raw typescript lambda", "aws lambda typescript performance".

giuseppe-trisciuoglio/aws-rds-spring-boot-integration

Provides patterns to configure AWS RDS (Aurora, MySQL, PostgreSQL) with Spring Boot applications. Configures HikariCP connection pools, implements read/write splitting, sets up IAM database authentication, enables SSL connections, and integrates with AWS Secrets Manager. Use when setting up RDS connections in Spring Boot, configuring connection pooling, or managing database credentials securely.

giuseppe-trisciuoglio/aws-sdk-java-v2-bedrock

Provides Amazon Bedrock patterns using AWS SDK for Java 2.x. Invokes foundation models (Claude, Llama, Titan), generates text and images, creates embeddings for RAG, streams real-time responses, and configures Spring Boot integration. Use when asking about Bedrock integration, Java SDK for AI models, AWS generative AI, Claude/Llama invocation, embeddings for RAG, or Spring Boot AI setup.

giuseppe-trisciuoglio/aws-sdk-java-v2-dynamodb

Provides Amazon DynamoDB patterns using AWS SDK for Java 2.x. Use when creating, querying, scanning, or performing CRUD operations on DynamoDB tables, working with indexes, batch operations, transactions, or integrating with Spring Boot applications.

giuseppe-trisciuoglio/aws-sdk-java-v2-kms

Provides AWS Key Management Service (KMS) patterns using AWS SDK for Java 2.x. Use when creating/managing encryption keys, encrypting/decrypting data, generating data keys, digital signing, key rotation, or integrating encryption into Spring Boot applications.

giuseppe-trisciuoglio/aws-sdk-java-v2-lambda

Provides AWS Lambda patterns using AWS SDK for Java 2.x. Use when invoking Lambda functions, creating/updating functions, managing function configurations, working with Lambda layers, or integrating Lambda with Spring Boot applications.

giuseppe-trisciuoglio/aws-sdk-java-v2-messaging

Provides AWS messaging patterns using AWS SDK for Java 2.x for SQS queues and SNS topics. Handles sending/receiving messages, FIFO queues, DLQ, subscriptions, and pub/sub patterns. Use when implementing messaging with SQS or SNS.

giuseppe-trisciuoglio/aws-sdk-java-v2-rds

Provides AWS RDS (Relational Database Service) management patterns using AWS SDK for Java 2.x. Use when creating, modifying, monitoring, or managing Amazon RDS database instances, snapshots, parameter groups, and configurations.

giuseppe-trisciuoglio/aws-sdk-java-v2-s3

Provides Amazon S3 patterns and examples using AWS SDK for Java 2.x. Use when working with S3 buckets, uploading/downloading objects, multipart uploads, presigned URLs, S3 Transfer Manager, object operations, or S3-specific configurations.

giuseppe-trisciuoglio/aws-sdk-java-v2-secrets-manager

Provides AWS Secrets Manager patterns for AWS SDK for Java 2.x, including secret retrieval, caching, rotation-aware access, and Spring Boot integration. Use when storing or reading secrets in Java services, replacing hardcoded credentials, or wiring secret-backed configuration into applications.

giuseppe-trisciuoglio/better-auth

Provides Better Auth integration patterns for NestJS backend and Next.js frontend with Drizzle ORM and PostgreSQL. Use when setting up Better Auth with NestJS backend, integrating Next.js App Router frontend, configuring Drizzle ORM schema, implementing social login (GitHub, Google), adding plugins (2FA, Organization, SSO, Magic Link, Passkey), implementing email/password authentication with session management, or creating protected routes and middleware.

giuseppe-trisciuoglio/chunking-strategy

Provides chunking strategies for RAG systems. Generates chunk size recommendations (256-1024 tokens), overlap percentages (10-20%), and semantic boundary detection methods. Validates semantic coherence and evaluates retrieval precision/recall metrics. Use when building retrieval-augmented generation systems, vector databases, or processing large documents.

giuseppe-trisciuoglio/clean-architecture

Provides implementation patterns for Clean Architecture, Hexagonal Architecture (Ports & Adapters), and Domain-Driven Design in Java 21+ Spring Boot 3.5+ applications. Use when structuring layered architectures, separating domain logic from frameworks, implementing ports and adapters, creating entities/value objects/aggregates, or refactoring monolithic codebases for testability and maintainability.

giuseppe-trisciuoglio/docs-updater

Provides automated documentation updates by analyzing git changes between the current branch and the last release tag. Performs git diff analysis to identify modifications, then updates README.md, CHANGELOG.md following Keep a Changelog standard, and discovers documentation folders for contextual updates. Use when preparing a release, maintaining documentation sync, or before creating a pull request. Triggers on "update docs", "update changelog", "sync documentation", "update readme", "prepare release documentation".

giuseppe-trisciuoglio/drawio-logical-diagrams

Creates professional logical flow diagrams and logical system architecture diagrams using draw.io XML format (.drawio files). Use when creating: (1) logical flow diagrams showing data/process flow between system components, (2) logical architecture diagrams representing system structure without cloud provider specifics, (3) BPMN process diagrams, (4) UML diagrams (class, sequence, activity), (5) data flow diagrams (DFD), (6) decision flowcharts, or (7) system interaction diagrams. This skill focuses on generic/abstract representations, not AWS/Azure-specific architectures (use aws-drawio-architecture-diagrams for cloud diagrams).

giuseppe-trisciuoglio/drizzle-orm-patterns

Provides comprehensive Drizzle ORM patterns for schema definition, CRUD operations, relations, queries, transactions, and migrations. Proactively use for any Drizzle ORM development including defining database schemas, writing type-safe queries, implementing relations, managing transactions, and setting up migrations with Drizzle Kit. Supports PostgreSQL, MySQL, SQLite, MSSQL, and CockroachDB.

giuseppe-trisciuoglio/github-issue-workflow

Provides a structured 8-phase workflow for resolving GitHub issues in Claude Code. Covers fetching issue details, analyzing requirements, implementing solutions, verifying correctness, performing code review, committing changes, and creating pull requests. Use when user asks to resolve, implement, work on, fix, or close a GitHub issue, or references an issue URL or number for implementation.

相關技能