claude-skills/

Anthropic公式スキル・プラグインの日本語ディレクトリ

last sync 22h ago
スキルOfficialdevelopment

🔧aws-sdk-swift-usage

プラグイン
aws-core

説明

AWS SDK for Swift の開発パターン。 次のような場合に使用: `aws-sdk-swift` パッケージを通じて AWS サービスを利用する Swift コードを記述する際。

原文を表示

AWS SDK for Swift development patterns. Use when writing Swift code that uses AWS services via aws-sdk-swift package.

ユースケース

  • AWS サービスを利用する Swift コードを記述するとき

本文(日本語訳)

AWS SDK for Swift

非同期コードの構造

すべての SDK オペレーションは非同期です。エントリポイントには @main を使用してください:

@main
struct Main {
    static func main() async throws {
        let client = try await S3Client()
        // ... 非同期オペレーション
    }
}

重要: 構造体ベースの Config 型を使用すること

S3ClientConfigurationDynamoDBClientConfiguration絶対に使用しないでください — これらは非推奨のクラスです。

必ず構造体ベースの Config 型を使用してください:

  • S3Client.S3ClientConfig(S3ClientConfiguration ではない)
  • DynamoDBClient.DynamoDBClientConfig(DynamoDBClientConfiguration ではない)
  • STSClient.STSClientConfig(STSClientConfiguration ではない)

Config のパラメータは宣言順に従う必要があります。Config を作成する際、region常に必須です。正確な順序はサービスクライアントのソースコードを確認してください。

// 正しい例 - 構造体ベースの config
let config = try await S3Client.S3ClientConfig(region: "us-west-2")
let client = S3Client(config: config)

// 誤った例 - 非推奨クラス
// let config = try await S3Client.S3ClientConfiguration(region: "us-west-2")

クライアントの作成

すべてのサービスクライアントは同じパターンに従います: <Service>Client<Service>Client.<Service>ClientConfig の組み合わせです。

リクエスト/レスポンスで使用するモデル型(構造体・列挙型)は <Service>ClientTypes 配下の名前空間に属しています:

  • S3ClientTypes.BucketS3ClientTypes.Object
  • DynamoDBClientTypes.AttributeValue
  • CloudWatchClientTypes.MetricDatumCloudWatchClientTypes.Dimension
import AWSS3
import AWSDynamoDB

// シンプルな方法 - リージョンを自動検出
let s3 = try await S3Client()
let dynamo = try await DynamoDBClient()

// リージョンを指定
let s3 = try S3Client(region: "us-west-2")

// config を使用 - パラメータは宣言順に従うこと
let config = try await S3Client.S3ClientConfig(
    useFIPS: true,
    awsRetryMode: .adaptive,
    maxAttempts: 5,
    region: "us-west-2"
)
let client = S3Client(config: config)

// カスタムエンドポイントと認証情報を使用
let config = try await S3Client.S3ClientConfig(
    awsCredentialIdentityResolver: resolver,
    region: "us-west-2",
    endpoint: "https://s3.custom-endpoint.com"
)

主な config パラメータ(宣言順に従うこと):

  • awsCredentialIdentityResolver — カスタム認証情報

  • useFIPS — FIPS エンドポイントを有効化

  • useDualStack — デュアルスタックエンドポイントを有効化

  • awsRetryMode — リトライ戦略(.adaptive.standard.legacy

  • maxAttempts — 最大リトライ回数

  • region — AWS リージョン

  • httpClientEngine — カスタム HTTP クライアント(HttpClientConfiguration パラメータが必要):

    import ClientRuntime
    let httpConfig = HttpClientConfiguration()
    let httpClient = URLSessionHTTPClient(httpClientConfiguration: httpConfig)
    let config = try await S3Client.S3ClientConfig(
        region: "us-east-1",
        httpClientEngine: httpClient
    )
    
  • endpoint — カスタムエンドポイント URL

サービス固有の config オプションや正確なパラメータ順序については、SDK 内の Sources/Services/AWS<Service>/Sources/AWS<Service>/<Service>Client.swift を確認してください。

クレデンシャルリゾルバー

import AWSSDKIdentity
import SmithyIdentity

// 静的クレデンシャル - クレデンシャルオブジェクトを直接渡す
let creds = AWSCredentialIdentity(accessKey: "AKIA...", secret: "...")
let resolver = StaticAWSCredentialIdentityResolver(creds)

// ロールの引き受け(Assume Role)- 基盤となるリゾルバーが必須
let underlying = try DefaultAWSCredentialIdentityResolverChain()
let resolver = try STSAssumeRoleAWSCredentialIdentityResolver(
    awsCredentialIdentityResolver: underlying,
    roleArn: "arn:aws:iam::123456789012:role/MyRole",
    sessionName: "session-name"
)

// config で使用
let config = try await S3Client.S3ClientConfig(
    awsCredentialIdentityResolver: resolver,
    region: "us-west-2"
)

Waiter

SmithyWaitersAPI をインポートしてください。WaiterOptions には maxWaitTime パラメータが必要です:

import AWSS3
import SmithyWaitersAPI

let client = try await S3Client()
_ = try await client.waitUntilBucketExists(
    options: WaiterOptions(maxWaitTime: 120.0),
    input: HeadBucketInput(bucket: "my-bucket")
)

ページネーション

let input = ListObjectsV2Input(bucket: "my-bucket")
for try await page in client.listObjectsV2Paginated(input: input) {
    for object in page.contents ?? [] {
        print(object.key ?? "")
    }
}

署名付き URL(Presigned URL)

let url = try await client.presignedURLForGetObject(
    input: GetObjectInput(bucket: "my-bucket", key: "file.pdf"),
    expiration: 3600
)

主なオペレーション

// オブジェクトのアップロード
_ = try await client.putObject(input: PutObjectInput(
    body: .data(data),
    bucket: "bucket",
    key: "key"
))

// オブジェクトの取得
let output = try await client.getObject(input: GetObjectInput(bucket: "bucket", key: "key"))
let data = try await output.body?.readData()

// バケット一覧の取得
let response = try await client.listBuckets(input: ListBucketsInput())
for bucket in response.buckets ?? [] {
    print(bucket.name ?? "")
}
原文(English)を表示

AWS SDK for Swift

Async Code Structure

All SDK operations are async. Use @main entry point:

@main
struct Main {
    static func main() async throws {
        let client = try await S3Client()
        // ... async operations
    }
}

CRITICAL: Use Struct Config Types

NEVER use S3ClientConfiguration or DynamoDBClientConfiguration - these are DEPRECATED classes.

ALWAYS use the struct-based config types:

  • S3Client.S3ClientConfig (not S3ClientConfiguration)
  • DynamoDBClient.DynamoDBClientConfig (not DynamoDBClientConfiguration)
  • STSClient.STSClientConfig (not STSClientConfiguration)

Config parameters MUST be in declaration order. Region is ALWAYS required when creating a config. Check the service client source for exact order.

// CORRECT - struct config
let config = try await S3Client.S3ClientConfig(region: "us-west-2")
let client = S3Client(config: config)

// WRONG - deprecated class
// let config = try await S3Client.S3ClientConfiguration(region: "us-west-2")

Client Creation

All service clients follow the same pattern: <Service>Client with <Service>Client.<Service>ClientConfig.

Model types (structs/enums used in requests/responses) are namespaced under <Service>ClientTypes:

  • S3ClientTypes.Bucket, S3ClientTypes.Object
  • DynamoDBClientTypes.AttributeValue
  • CloudWatchClientTypes.MetricDatum, CloudWatchClientTypes.Dimension
import AWSS3
import AWSDynamoDB

// Simple - auto-detects region
let s3 = try await S3Client()
let dynamo = try await DynamoDBClient()

// With region
let s3 = try S3Client(region: "us-west-2")

// With config - parameters must be in declaration order
let config = try await S3Client.S3ClientConfig(
    useFIPS: true,
    awsRetryMode: .adaptive,
    maxAttempts: 5,
    region: "us-west-2"
)
let client = S3Client(config: config)

// With custom endpoint and credentials
let config = try await S3Client.S3ClientConfig(
    awsCredentialIdentityResolver: resolver,
    region: "us-west-2",
    endpoint: "https://s3.custom-endpoint.com"
)

Common config parameters (MUST follow declaration order):

  • awsCredentialIdentityResolver - Custom credentials

  • useFIPS - Enable FIPS endpoints

  • useDualStack - Enable dual-stack endpoints

  • awsRetryMode - Retry strategy (.adaptive, .standard, .legacy)

  • maxAttempts - Max retry attempts

  • region - AWS region

  • httpClientEngine - Custom HTTP client (requires HttpClientConfiguration parameter):

    import ClientRuntime
    let httpConfig = HttpClientConfiguration()
    let httpClient = URLSessionHTTPClient(httpClientConfiguration: httpConfig)
    let config = try await S3Client.S3ClientConfig(
        region: "us-east-1",
        httpClientEngine: httpClient
    )
    
  • endpoint - Custom endpoint URL

For service-specific config options or exact parameter order, check Sources/Services/AWS<Service>/Sources/AWS<Service>/<Service>Client.swift in the SDK.

Credential Resolvers

import AWSSDKIdentity
import SmithyIdentity

// Static credentials - pass credential object directly
let creds = AWSCredentialIdentity(accessKey: "AKIA...", secret: "...")
let resolver = StaticAWSCredentialIdentityResolver(creds)

// Assume role - REQUIRES underlying resolver
let underlying = try DefaultAWSCredentialIdentityResolverChain()
let resolver = try STSAssumeRoleAWSCredentialIdentityResolver(
    awsCredentialIdentityResolver: underlying,
    roleArn: "arn:aws:iam::123456789012:role/MyRole",
    sessionName: "session-name"
)

// Use in config
let config = try await S3Client.S3ClientConfig(
    awsCredentialIdentityResolver: resolver,
    region: "us-west-2"
)

Waiters

Import SmithyWaitersAPI. WaiterOptions requires maxWaitTime parameter:

import AWSS3
import SmithyWaitersAPI

let client = try await S3Client()
_ = try await client.waitUntilBucketExists(
    options: WaiterOptions(maxWaitTime: 120.0),
    input: HeadBucketInput(bucket: "my-bucket")
)

Pagination

let input = ListObjectsV2Input(bucket: "my-bucket")
for try await page in client.listObjectsV2Paginated(input: input) {
    for object in page.contents ?? [] {
        print(object.key ?? "")
    }
}

Presigned URLs

let url = try await client.presignedURLForGetObject(
    input: GetObjectInput(bucket: "my-bucket", key: "file.pdf"),
    expiration: 3600
)

Common Operations

// Put object
_ = try await client.putObject(input: PutObjectInput(
    body: .data(data),
    bucket: "bucket",
    key: "key"
))

// Get object
let output = try await client.getObject(input: GetObjectInput(bucket: "bucket", key: "key"))
let data = try await output.body?.readData()

// List buckets
let response = try await client.listBuckets(input: ListBucketsInput())
for bucket in response.buckets ?? [] {
    print(bucket.name ?? "")
}

原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。