

Amazon FSx File Gateway 不再提供給新客戶。FSx File Gateway 的現有客戶可以繼續正常使用服務。如需類似 FSx File Gateway 的功能，請造訪[此部落格文章](https://aws.amazon.com/blogs/storage/switch-your-file-share-access-from-amazon-fsx-file-gateway-to-amazon-fsx-for-windows-file-server/)。

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

# 取得閘道的啟用金鑰
<a name="get-activation-key"></a>

若要接收閘道的啟用金鑰，請向閘道虛擬機器 (VM) 發出網頁請求。虛擬機器會傳回包含啟用金鑰的重新導向，該重新導向會當做 `ActivateGateway` API 動作的其中一個參數傳遞，以指定閘道的組態。如需詳細資訊，請參閱 *Storage Gateway API 參考資料*中的 [ActivateGateway](https://docs.aws.amazon.com/storagegateway/latest/APIReference/API_ActivateGateway.html)。

**注意**  
如果未使用，閘道啟用金鑰會在 30 分鐘內過期。

您對閘道 VM 提出的請求包含進行啟用 AWS 的區域。重新導向在回應中傳回的 URL 會包含稱為 `activationkey` 的查詢字串參數。此查詢字串參數便是您的啟用金鑰。查詢字串的格式如下：`http://gateway_ip_address/?activationRegion=activation_region`。此查詢的輸出傳回啟用區域和金鑰。

此 URL 也包含 `vpcEndpoint` 使用 VPC 端點類型連線之閘道的 VPC 端點識別碼。

**注意**  
 AWS Storage Gateway硬體設備、VM 映像範本和 Amazon EC2 Amazon Machine Image (AMI) 已預先設定 HTTP 服務，以接收和回應此頁面所述的 Web 請求。您不需要或建議您在閘道上安裝任何其他服務。

**Topics**
+ [Linux (curl)](#get-activation-key-linux-curl)
+ [Linux (bash/zsh)](#get-activation-key-linux)
+ [Microsoft Windows PowerShell](#get-activation-key-powershell)
+ [使用本機主控台](#using-local-console)

## Linux (curl)
<a name="get-activation-key-linux-curl"></a>

以下範例顯示如何使用 Linux (curl) 取得啟用金鑰。

**注意**  
將反白顯示的變數取代為閘道的實際值。可接受的值如下：  
*gateway\$1ip\$1address*：例如，閘道器的 IPV4 地址 `172.31.29.201`
*gateway\$1type* - 您要啟用的閘道類型，例如 `STORED`、`CACHED`、`FILE_S3`、 `VTL`或 `FILE_FSX_SMB`。
*region\$1code*：您要啟用閘道的區域。請參閱《AWS 一般參考指南》**中的[區域端點](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints)。如果未指定此參數，或提供的值拼字錯誤或不符合有效區域，則命令會預設為`us-east-1`區域。
*vpc\$1endpoint*：例如，閘道的 VPC 端點名稱 `vpce-050f90485f28f2fd0-iep0e8vq.storagegateway.us-west-2.vpce.amazonaws.com`。

**若要取得公用端點的啟用金鑰：**

```
curl "http://gateway_ip_address/?activationRegion=region_code&no_redirect"
```

**若要取得 VPC 端點的啟用金鑰：**

```
curl "http://gateway_ip_address/?activationRegion=region_code&vpcEndpoint=vpc_endpoint&no_redirect"
```

## Linux (bash/zsh)
<a name="get-activation-key-linux"></a>

下列範例顯示如何使用 Linux (bash/zsh) 擷取 HTTP 回應、剖析 HTTP 標頭及取得啟用金鑰的方式。

```
  
function get-activation-key() {
  local ip_address=$1
  local activation_region=$2
  if [[ -z "$ip_address" || -z "$activation_region" || -z "$gateway_type" ]]; then
    echo "Usage: get-activation-key ip_address activation_region gateway_type"
    return 1
  fi

  if redirect_url=$(curl -f -s -S -w '%{redirect_url}' "http://$ip_address/?activationRegion=$activation_region&gatewayType=$gateway_type"); then
    activation_key_param=$(echo "$redirect_url" | grep -oE 'activationKey=[A-Z0-9-]+')
    echo "$activation_key_param" | cut -f2 -d=
  else
    return 1
  fi
}
```

## Microsoft Windows PowerShell
<a name="get-activation-key-powershell"></a>

下列範例顯示如何使用 Microsoft Windows PowerShell 擷取 HTTP 回應、剖析 HTTP 標頭及取得啟用金鑰的方式。

```
function Get-ActivationKey {
  [CmdletBinding()]
  Param(
    [parameter(Mandatory=$true)][string]$IpAddress, 
    [parameter(Mandatory=$true)][string]$ActivationRegion,
    [parameter(Mandatory=$true)][string]$GatewayType
  )
  PROCESS {
    $request = Invoke-WebRequest -UseBasicParsing -Uri "http://$IpAddress/?activationRegion=$ActivationRegion&gatewayType=$GatewayType" -MaximumRedirection 0 -ErrorAction SilentlyContinue
    if ($request) {
      $activationKeyParam = $request.Headers.Location | Select-String -Pattern "activationKey=([A-Z0-9-]+)"
      $activationKeyParam.Matches.Value.Split("=")[1]
    }
  }
}
```

## 使用本機主控台
<a name="using-local-console"></a>

下列如何使用本機主控台來產生和顯示啟用金鑰。

**從本機主控台取得閘道的啟用金鑰**

1. 以*管理員*身分登入您的本機主控台。

1. 登入並查看 **AWS 設備啟用 - 設定**主功能表後，選取 `0` 以選擇**取得啟用金鑰**。

1. 為閘道系列選項選取 **Storage Gateway**。

1. 出現提示時，輸入您要啟用閘道 AWS 區域 的 。

1. 輸入 `1` 公用端點或 `2` VPC 端點做為網路類型。

1. 輸入 `1` 標準或 `2` 美國聯邦資訊處理標準 (FIPS) 做為端點類型。