过去,您可以在web控制台上的AWS存储网关中查看磁带的标记,但现在看来AWS已经删除了该选项。查看标签的唯一方法是单独选择每个磁带,然后单击标签选项卡。
我有100多个磁带,手动这样做会很费时。是否有命令可以输出每个磁带条形码及其相关标签的列表?
或者,我们只在所有这些磁带上使用大约10个标记(每个磁带一个标记),我尝试使用Python/boto3 3脚本(我不是python古鲁)输出特定标记的所有磁带,遗憾的是,下面的脚本没有完全工作。它会输出一些磁带,但不是所有东西。例如,如果我搜索标签“仓库”,它将返回大约8磁带-这听起来不对。因此,在AWS控制台中手动查看时,我已经手动找到了带有此标记的3-4磁带,并且没有使用以下代码在列表中返回:
#Import the boto3 library
import boto3
#Create the tape gateway client
tgw_client = boto3.client('storagegateway')
#Create a list of the tapes
tapes = tgw_client.list_tapes()['TapeInfos']
#Create a for loop to process each tape in the tapes list
for tape in tapes:
#Set the TapeARN variable
tape_arn = tape['TapeARN']
#Describe the tags for the tape using the tape ARN
tape_tag = tgw_client.list_tags_for_resource(ResourceARN = tape_arn)
#Exception handing
try:
#Check to see if the first tag value matches job001
if tape_tag['Tags'][0]['Value'] == 'Warehouse':
#If the tag value matches job001, then print the list_tags_for_resource response for that tape
print(tape_tag)
#Ignore tapes which do not have the job001 tag
else:
pass
except:
pass任何帮助获得磁带和标签的输出或如何修复这个python脚本将是非常感谢的!
发布于 2022-01-20 23:58:47
脚本没有返回所有结果,因为帐户有206个磁带实例,list_tapes方法默认返回最大值为100。要处理这个问题并提取完整的列表,我们需要评估list_tapes响应,并使用标记元素进行后续请求,以检索下一组磁带。
下面是列出所有Lambda函数的参考脚本,这些函数可以很容易地更新以从Storage中提取磁带实例。只需更新客户端和响应映射,然后添加您自己的评估逻辑。
import boto3
def list_functions(marker):
try:
client = boto3.client('lambda')
if marker is not None:
print("Retrieving next page...")
response = client.list_functions(
Marker=marker,
)
else:
print("Retrieving first page..")
response = client.list_functions(
)
return response
except Exception as e: print(e)
def runtime():
try:
flist = []
marker = None
data = list_functions(marker)
if 'NextMarker' in data:
marker = data['NextMarker']
else:
marker = None
for i in data['Functions']:
flist.append(i['FunctionName'])
while marker is not None:
if '==' in marker:
data = list_functions(marker)
if 'NextMarker' in data:
marker = data['NextMarker']
else:
marker = None
for i in data['Functions']:
flist.append(i['FunctionName'])
else:
marker = None
print(flist)
except Exception as e: print(e)
runtime()https://stackoverflow.com/questions/70793239
复制相似问题