

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 提出請求
<a name="making-requests"></a>

使用 服務用戶端向 提出請求 AWS 服務。 適用於 Kotlin 的 AWS SDK 提供符合[類型安全建置器](https://kotlinlang.org/docs/type-safe-builders.html)模式的網域特定語言 (DSLs) 來建立請求。請求的巢狀結構也可以透過其 DSLs存取。

下列範例示範如何建立 Amazon DynamoDB [createTable](https://docs.aws.amazon.com/sdk-for-kotlin/api/latest/dynamodb/aws.sdk.kotlin.services.dynamodb/create-table.html) 操作輸入：

```
val ddb = DynamoDbClient.fromEnvironment()

val req = CreateTableRequest {
    tableName = name
    keySchema = listOf(
        KeySchemaElement {
            attributeName = "year"
            keyType = KeyType.Hash
        },
        KeySchemaElement {
            attributeName = "title"
            keyType = KeyType.Range
        }
    )

    attributeDefinitions = listOf(
        AttributeDefinition {
            attributeName = "year"
            attributeType = ScalarAttributeType.N
        },
        AttributeDefinition {
            attributeName = "title"
            attributeType = ScalarAttributeType.S
        }
    )
    
    // You can configure the `provisionedThroughput` member
    // by using the `ProvisionedThroughput.Builder` directly:
    provisionedThroughput {
        readCapacityUnits = 10
        writeCapacityUnits = 10
    }
}

val resp = ddb.createTable(req)
```

## 服務介面 DSL 過載
<a name="service-interface-dsl-overloads"></a>

服務用戶端界面上的每個非串流操作都有 DSL 超載，因此您不需要建立個別的請求。

使用過載函數建立 Amazon Simple Storage Service (Amazon S3) 儲存貯體的範例：

```
s3Client.createBucket {    // this: CreateBucketRequest.Builder
    bucket = newBucketName
}
```

這相當於：

```
val request = CreateBucketRequest {    // this: CreateBucketRequest.Builder 
    bucket = newBucketName 
}

s3client.createBucket(request)
```

## 沒有必要輸入的請求
<a name="requests-no-required-inputs"></a>

不需要輸入的操作可以呼叫，而無需傳遞請求物件。這通常適用於清單類型操作，例如 Amazon S3 `listBuckets` API 操作。

 例如，以下三個陳述式是相等的：

```
s3Client.listBuckets(ListBucketsRequest {
  // Construct the request object directly.
})
s3Client.listBuckets {
  // DSL builder without explicitly setting any arguments.
}
s3Client.listBuckets()
```