

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

# CloudFront SaaS Manager 屬性的 helper 方法
<a name="saas-specific-logic-function-code"></a>

使用 CloudFront SaaS Manager 的下列 helper 函數，在您建立的函數中擷取多租用戶分佈的值。若要在此頁面上使用範例，您必須先使用 JavaScript 執行時期 2.0 建立 CloudFront 函數。如需詳細資訊，[適用於 CloudFront Functions 的 JavaScript 執行時期 2.0 功能](functions-javascript-runtime-20.md)。

**Topics**
+ [連線群組](#connection-groups-helper-function)
+ [分佈租用戶](#distribution-tenants-helper-functions)

## 連線群組
<a name="connection-groups-helper-function"></a>

與分佈租用戶相關聯的連線群組具有網域名稱。

若要取得此值，請使用事件物件 `context` 子物件的 `endpoint` 欄位。

**請求**

```
const value = event.context.endpoint;
```

**回應**

回應是包含連線群組網域名稱的 `string`，例如 d111111abcdef8.cloudfront.net。只有當您的函數被調用具有相關聯連線群組的多租用戶分佈時，`endpoint` 欄位才會出現。如需詳細資訊，請參閱[內容物件](functions-event-structure.md#functions-event-structure-context)。

## 分佈租用戶
<a name="distribution-tenants-helper-functions"></a>

CloudFront Functions 有一個模組，可讓您存取特定的分佈租用戶值。

若要使用此模組，請在函數程式碼的第一行中包含下列陳述式：

```
import cf from 'cloudfront';
```

您只能在 `handler` 函數中直接或透過任何巢狀呼叫函數使用下列範例。

### `distributionTenant.id` 欄位
<a name="distribution-tenants-field"></a>

使用此欄位來取得分佈租用戶 ID 的值。

**請求**

```
const value = cf.distributionTenant.id;
```

**回應**

回應是包含分佈租用戶 ID 的 `string`，例如 `dt_1a2b3c4d5e6f7`。

**錯誤處理**

如果您的函數是針對標準分佈調用，則指定 `distributionTenant.id` 欄位將傳回 `distributionTenant module is not available` 類型錯誤。若要處理此使用案例，您可以將 `try` 和 `catch` 區塊新增至程式碼。

### `distributionTenant.parameters.get()` 方法
<a name="distribution-tenant-parameters-get-method"></a>

使用此方法可傳回您指定之分佈租用戶參數名稱的值。

```
distributionTenant.parameters.get("key");
```

`key`：您要為其擷取值的分佈租用戶參數名稱。

**請求 **

```
const value = distributionTenant.parameters.get("key");
```

**回應**

回應是 `string`，其中包含分佈租用戶參數的值。例如，如果您的鍵名稱為 `TenantPath`，則此參數的值可能是 `tenant1`。

**錯誤處理**

您可能會收到下列錯誤：
+ 如果您的函數是針對標準分佈調用，則 `distributionTenant.parameters.get()` 方法將傳回 `distributionTenant module is not available` 類型錯誤。
+ 當您指定的分佈租用戶參數不存在時，會傳回 `DistributionTenantParameterKeyNotFound` 錯誤。

若要管理這些使用案例，您可以將 `try` 和 `catch` 區塊新增至程式碼。