

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

# DocumentDB
<a name="sam-property-function-documentdb"></a>

描述`DocumentDB`事件來源類型的物件。如需詳細資訊，請參閱《 *AWS Lambda 開發人員指南*》中的[搭配使用 AWS Lambda 與 Amazon DocumentDB](https://docs.aws.amazon.com/lambda/latest/dg/with-documentdb.html)。

## 語法
<a name="sam-property-function-documentdb-syntax"></a>

若要在 AWS SAM 範本中宣告此實體，請使用下列語法。

### YAML
<a name="sam-property-function-documentdb-syntax-yaml"></a>

```
BatchSize: Integer
Cluster: [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-filtercriteria.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-filtercriteria.html)
CollectionName: String
DatabaseName: String
Enabled: Boolean
FilterCriteria: [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-filtercriteria.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-filtercriteria.html)
FullDocument: String
KmsKeyArn: String  
MaximumBatchingWindowInSeconds: Integer
SecretsManagerKmsKeyId: String
SourceAccessConfigurations: List
StartingPosition: String
StartingPositionTimestamp: Double
```

## Properties
<a name="sam-property-function-documentdb-properties"></a>

 `BatchSize`   <a name="sam-function-documentdb-batchsize"></a>
要在單一批次中擷取的最大項目數。  
*類型*：整數  
*必要*：否  
*CloudFormation 相容性*：此屬性會直接傳遞至 `AWS::Lambda::EventSourceMapping` 資源的 `[ BatchSize](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-batchsize)` 屬性。

 `Cluster`   <a name="sam-function-documentdb-cluster"></a>
Amazon DocumentDB 叢集的 Amazon Resource Name (ARN)。  
*類型：*字串  
*必要*：是  
*CloudFormation 相容性*：此屬性會直接傳遞至 `AWS::Lambda::EventSourceMapping` 資源的 `[ EventSourceArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-eventsourcearn)` 屬性。

 `CollectionName`   <a name="sam-function-documentdb-collectionname"></a>
要在資料庫內使用的集合名稱。如果您未指定集合，Lambda 會使用所有集合。  
*類型：*字串  
*必要*：否  
*CloudFormation 相容性*：此屬性會直接傳遞至 `AWS::Lambda::EventSourceMapping``DocumentDBEventSourceConfig`資料類型的 `[ CollectionName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-documentdbeventsourceconfig.html#cfn-lambda-eventsourcemapping-documentdbeventsourceconfig-collectionname)` 屬性。

 `DatabaseName`   <a name="sam-function-documentdb-databasename"></a>
Amazon DocumentDB 叢集內要使用的資料庫名稱。  
*類型：*字串  
*必要*：是  
*CloudFormation 相容性*：此屬性會直接傳遞至 `AWS::Lambda::EventSourceMapping``DocumentDBEventSourceConfig`資料類型的 `[ DatabaseName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-documentdbeventsourceconfig.html#cfn-lambda-eventsourcemapping-documentdbeventsourceconfig-databasename)` 屬性。

 `Enabled`   <a name="sam-function-documentdb-enabled"></a>
如果為 `true`，則事件來源映射為作用中。若要暫停輪詢和調用，請將 設定為 `false`。  
*類型*：布林值  
*必要*：否  
*CloudFormation 相容性*：此屬性會直接傳遞至 `AWS::Lambda::EventSourceMapping` 資源的 `[ Enabled](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-enabled)` 屬性。

 `FilterCriteria`   <a name="sam-function-documentdb-filtercriteria"></a>
定義判斷 Lambda 是否應處理事件之條件的物件。如需詳細資訊，請參閱《 *AWS Lambda 開發人員指南*》中的 [ Lambda 事件篩選](https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventfiltering.html)。  
*類型*：[FilterCriteria](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-filtercriteria.html)  
*必要*：否  
*CloudFormation 相容性*：此屬性會直接傳遞至 `AWS::Lambda::EventSourceMapping` 資源的 `[ FilterCriteria](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-filtercriteria.html)` 屬性。

 `FullDocument`   <a name="sam-function-documentdb-fulldocument"></a>
決定 Amazon DocumentDB 在文件更新操作期間傳送到事件串流的內容。如果設定為 `UpdateLookup`，Amazon DocumentDB 會傳送描述變更的差異，以及整個文件的副本。否則，Amazon DocumentDB 只會傳送包含變更的部分文件。  
*類型：*字串  
*必要*：否  
*CloudFormation 相容性*：此屬性會直接傳遞至 `AWS::Lambda::EventSourceMapping``DocumentDBEventSourceConfig`資料類型的 `[ FullDocument](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-documentdbeventsourceconfig.html#cfn-lambda-eventsourcemapping-documentdbeventsourceconfig-fulldocument)` 屬性。

 `KmsKeyArn`   <a name="sam-function-documentdb-kmskeyarn"></a>
金鑰的 Amazon Resource Name (ARN)，用於加密與此事件相關的資訊。  
*類型：*字串  
*必要*：否  
*CloudFormation 相容性*：此屬性會直接傳遞至 `AWS::Lambda::EventSourceMapping` 資源的 `[KmsKeyArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-kmskeyarn)` 屬性。

 `MaximumBatchingWindowInSeconds`   <a name="sam-function-documentdb-maximumbatchingwindowinseconds"></a>
調用函式前收集記錄的最長時間 (單位為秒)。  
*類型*：整數  
*必要*：否  
*CloudFormation 相容性*：此屬性會直接傳遞至 `AWS::Lambda::EventSourceMapping` 資源的 `[ MaximumBatchingWindowInSeconds](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-maximumbatchingwindowinseconds)` 屬性。

 `SecretsManagerKmsKeyId`   <a name="sam-function-documentdb-secretsmanagerkmskeyid"></a>
 AWS Secrets Manager 的客戶受管金鑰的 AWS Key Management Service (AWS KMS) 金鑰 ID。當您使用 Secrets Manager 的客戶受管金鑰搭配不包含 `kms:Decrypt`許可的 Lambda 執行角色時，此為必要項目。  
此屬性的值是 UUID。例如：`1abc23d4-567f-8ab9-cde0-1fab234c5d67`。  
*類型：*字串  
*必要*：有條件  
*CloudFormation 相容性*：此屬性對 是唯一的 AWS SAM ，並且沒有同等 CloudFormation 的。

 `SourceAccessConfigurations`   <a name="sam-function-documentdb-sourceaccessconfigurations"></a>
身分驗證通訊協定或虛擬主機的陣列。使用 [ SourceAccessConfigurations](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-sourceaccessconfiguration.html) 資料類型指定此項目。  
對於`DocumentDB`事件來源類型，唯一的有效組態類型為 `BASIC_AUTH`。  
+ `BASIC_AUTH` – 存放代理程式登入資料的 Secrets Manager 秘密。對於此類型，登入資料必須採用下列格式：`{"username": "your-username", "password": "your-password"}`。僅允許一個 類型的物件`BASIC_AUTH`。
*類型：*清單  
*必要*：是  
*CloudFormation 相容性*：此屬性會直接傳遞至 `AWS::Lambda::EventSourceMapping` 資源的 `[ SourceAccessConfigurations](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-sourceaccessconfigurations)` 屬性。

 `StartingPosition`   <a name="sam-function-documentdb-startingposition"></a>
要從中開始讀取的串流位置。  
+ `AT_TIMESTAMP` – 指定從中開始讀取記錄的時間。
+ `LATEST` – 唯讀新記錄。
+ `TRIM_HORIZON` – 處理所有可用的記錄。
*類型：*字串  
*必要*：是  
*CloudFormation 相容性*：此屬性會直接傳遞至 `AWS::Lambda::EventSourceMapping` 資源的 `[ StartingPosition](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-startingposition)` 屬性。

 `StartingPositionTimestamp`   <a name="sam-function-documentdb-startingpositiontimestamp"></a>
開始讀取的時間，以 Unix 時間秒為單位。定義 `StartingPositionTimestamp` `StartingPosition` 何時指定為 `AT_TIMESTAMP`。  
*類型*：Double  
*必要*：否  
*CloudFormation 相容性*：此屬性會直接傳遞至 `AWS::Lambda::EventSourceMapping` 資源的 `[ StartingPositionTimestamp](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-startingpositiontimestamp)` 屬性。

## 範例
<a name="sam-property-function-documentdb-examples"></a>

### Amazon DocumentDB 事件來源
<a name="sam-property-function-documentdb-examples-example1"></a>

```
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
...
Resources:
  MyFunction:
    Type: AWS::Serverless::Function
    Properties:
    ...
      Events:
        MyDDBEvent:
          Type: DocumentDB
          Properties:
            Cluster: "arn:aws:rds:us-west-2:123456789012:cluster:docdb-2023-01-01"
            BatchSize: 10
            MaximumBatchingWindowInSeconds: 5
            DatabaseName: "db1"
            CollectionName: "collection1"
            FullDocument: "UpdateLookup"
            SourceAccessConfigurations:
              - Type: BASIC_AUTH
                URI: "arn:aws:secretsmanager:us-west-2:123456789012:secret:doc-db"
```