取得您閘道的啟用金鑰 - AWSStorage Gateway

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

取得您閘道的啟用金鑰

若要取得您閘道的啟用金鑰,您必須向閘道 VM 傳送 Web 請求,便會傳回包含啟用金鑰的重新導向。此啟用金鑰會做為其中一項參數傳遞到 ActivateGateway API 動作,指定您閘道的組態。如需詳細資訊,請參閱「」ActivateGateway中的Storage Gateway API 參考

您向閘道 VM 發送的請求包含AWS激活發生的區域。重新導向在回應中傳回的 URL 會包含稱為 activationkey 的查詢字串參數。此查詢字串參數便是您的啟用金鑰。查詢字串的格式如下: http://gateway_ip_address/?activationRegion=activation_region

AWS CLI

若您尚未執行此作業,您必須安裝及設定 AWS CLI。若要執行此作業,請遵循AWS Command Line Interface 使用者指南中的這些說明:

下列範例顯示如何使用AWS CLI取得 HTTP 回應,剖析 HTTP 標頭及取得啟用金鑰。

wget 'ec2_instance_ip_address/?activationRegion=eu-west-2' 2>&1 | \ grep -i location | \ grep -i key | \ cut -d'=' -f2 |\ cut -d'&' -f1

Linux (bash/zsh)

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

function get-activation-key() { local ip_address=$1 local activation_region=$2 if [[ -z "$ip_address" || -z "$activation_region" ]]; then echo "Usage: get-activation-key ip_address activation_region" return 1 fi if redirect_url=$(curl -f -s -S -w '%{redirect_url}' "http://$ip_address/?activationRegion=$activation_region"); 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

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

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