我有脚本,它列出了所有用户池,但我正在尝试根据池的 ID 进行过滤。 我是 python 的新手(学习新的语言(,但过滤器不起作用。
import boto3
client = boto3.client('cognito-idp')
def user_pool():
response = client.list_user_pools(
NextToken="PaginationKeyType",
MaxResults=20
)
def filter_user_pools():
listpools = client.list_user_pools.filter(
Filters=[{'Id': 'UserPoolId'}])
for list in listpools:
print(list.Id)
Synatx如下,我正在尝试过滤
{'UserPools': [{'Id': 'eu-west-1_asdasdg34', 'Name': 'JenkinsDevelopMarketplace', 'LambdaConfig': {'PreSignUp':...
到目前为止,它正在抱怨过滤器。
我正在尝试过滤"eu-west-1"。
任何建议,适用。
谢谢
我希望你几乎是对的。只是缺乏蟒蛇经验。
lambda x: 'eu-west-1' in x['Id']
,它取参数 x 并根据条件 ('eu-west-1' in x['Id']
( 返回True/False
。
def get_user_pools():
response = client.list_user_pools(
NextToken="PaginationKeyType",
MaxResults=20
)
return response['UserPools'] # this will return list of pool
pools = get_user_pools()
filtered_list = filter(lambda x: 'eu-west-1' in x['Id'], pools) # can change eu-west-1
print(filtered_list)