获取网关的激活密钥 - AmazonStorage Gateway
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

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

获取网关的激活密钥

要获取网关的激活密钥,需要向网关 VM 发出一个 Web 请求,它会返回一个包含激活密钥的重定向。此激活密钥作为一个参数传递到 ActivateGateway API 操作以指定网关的配置。有关更多信息,请参阅 。ActivateGateway中的Storage Gateway API 参考.

您向网关 VM 发出的请求包含Amazon激活发生的区域。响应中重定向返回的 URL 包含称为 activationkey 的查询字符串参数。此查询字符串参数是您的激活密钥。此查询字符串的格式如下所示: http://gateway_ip_address/?activationRegion=activation_region

Amazon CLI

如果您尚未安装和配置 Amazon CLI,则必须先执行此操作。为此,请按照 Amazon Command Line Interface 用户指南中的这些指示操作:

以下示例说明了如何使用Amazon 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] } } }