

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

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

使用服务客户端向发出请求 AWS 服务。按照[类型安全的生成器](https://kotlinlang.org/docs/type-safe-builders.html)模式 适用于 Kotlin 的 AWS SDK 提供特定于域的语言 (DSLs) 来创建请求。也可以通过其访问请求的嵌套结构 DSLs。

以下示例说明如何创建 Amazon Dynamo [DB](https://docs.aws.amazon.com/sdk-for-kotlin/api/latest/dynamodb/aws.sdk.kotlin.services.dynamodb/create-table.html) CreateTable 操作输入：

```
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 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()
```