得到以下代码,它显示了我所有的存储网关。我只需要获取 1 个网关的信息
import boto3
sg = boto3.client('storagegateway', 'us-east-1')
sg.list(gateways)
print (sg.list_gateways)
知道如何过滤并仅打印特定的 gw 吗?
得到以下代码,它显示了我所有的存储网关。我只需要获取 1 个网关的信息
import boto3
sg = boto3.client('storagegateway', 'us-east-1')
sg.list(gateways)
print (sg.list_gateways)
知道如何过滤并仅打印特定的 gw 吗?
尝试这样的事情来过滤特定的网关名称......
import boto3
sg = boto3.client('storagegateway', 'us-east-1')
response = sg.list_gateways()
for gw in response['Gateways']:
if gw['GatewayName'] == 'YOUR_GATEWAY_NAME':
print(gw)
您也可以通过更新 IF 语句过滤其他响应元素(例如 ARN、ID 等)。此外,如果您有超过 100 个存储网关实例,则需要处理 Marker 元素来检索所有结果。有关更多信息,请参阅此处的 Boto3 文档: