gpt4 book ai didi

python - 如何在 Python 中使用 If 语句查找特定服务名称

转载 作者:太空宇宙 更新时间:2023-11-03 20:06:00 26 4
gpt4 key购买 nike

我是 AWS 中的 python boto3 函数的新手。我想知道如何搜索特定的 serviceNameArn (u'arn:aws:ecs:us-east-1:778784494011:service/RITS-selenium-node-chrome-service-Service-5ZADFVZNNCFJ)在下面的 AWS ECS 集群中运行的服务列表中,键值对为:{"Browser":"Chrome"}。

这是我的代码:

import boto3
from flask import Flask
from flask import request
from flask import jsonify, make_response
import requests
import json

browser='chrome'
CLUSTER = 'ECS-QEAUTOMATION-HYBRID-DEV'
client = boto3.client('ecs')
list_services = client.list_services(cluster=CLUSTER)
print(list_services['serviceArns'])
for x in list_services:
if browser in x:
x.servicename
print(x.servicename)

输出:我仍然收到集群中运行的所有服务的列表,除了一个:

[u'arn:aws:ecs:us-east-1:778784494011:service/RITS-selenium-hub-service-Service-1ESSGHC030KT6', u'arn:aws:ecs:us-east-1:778784494011:service/RITS-selenium-node-chrome-service-Service-5ZADFVZNNCFJ', u'arn:aws:ecs:us-east-1:778784494011:service/RITS-sonarqube-service-Service-1359LNU242V25', u'arn:aws:ecs:us-east-1:778784494011:service/RITS-jmetermaster-service-Service-1JOAYPCN8KNZI', u'arn:aws:ecs:us-east-1:778784494011:service/RITS-jmeterslave-service-Service-1PIAW69QGP9F8', u'arn:aws:ecs:us-east-1:778784494011:service/RITS-selenium-node-firefox-service-Service-QVDLJQ423TX7', u'arn:aws:ecs:us-east-1:778784494011:service/RITS-dashboard-service-Service-1T8VSPQ28ZAGO', u'arn:aws:ecs:us-east-1:778784494011:service/RITS-commandcenter-service-Service-1MVRK6EPDL3MN']

最佳答案

试试这个。看起来您正在循环遍历 list_services 而不是 arns。

browser='chrome'
CLUSTER = 'ECS-QEAUTOMATION-HYBRID-DEV'
client = boto3.client('ecs')
list_services = client.list_services(cluster=CLUSTER)
service_arns = list_services['serviceArns']
print(service_arns )
for service_arn in service_arns:
if browser in service_arn:
print(service_arn)

关于python - 如何在 Python 中使用 If 语句查找特定服务名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58963399/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com