【问题标题】:Boto3 Amplify list appsBoto3 放大列表应用程序
【发布时间】:2021-12-06 08:04:52
【问题描述】:

我有很多我想通过 Lambda 管理的放大应用程序。 boto3中的cli命令aws amplify list-apps的等价物是什么,我进行了多次尝试,但没有一个适合我。 我使用nextToken 的代码看起来像这样:

amplify = boto3.client('amplify')
apps = amplify.list_apps()
print(apps)
print('First token is: ', apps['nextToken'])

while 'nextToken' in apps:
    apps = amplify.list_apps(nextToken=apps['nextToken'])
    print('=====NEW APP=====')
    print(apps)
    print('=================')

然后我尝试使用分页器,例如:

paginator = amplify.get_paginator('list_apps')
response_iterator = paginator.paginate(
    PaginationConfig={
        'MaxItems': 100,
        'PageSize': 100
    }
)

for i in response_iterator:
    print(i)

两次尝试都抛出了不一致的输出。第一个是打印第一个令牌和第二个条目,仅此而已。第二个只给出第一个条目。

使用更多尝试信息 + 输出进行编辑。下面是一段代码:

apps = amplify.list_apps()
print(apps)
print('---------------')
new_app = amplify.list_apps(nextToken=apps['nextToken'], maxResults=100)
print(new_app)
print('---------------')```

Returns (some sensitive output bits were removed):

EVG_long_token_x4gbDGaAWGPGOASRtJPSI='}
---------------
{'ResponseMetadata': {'RequestId': 'f6...e9eb', 'HTTPStatusCode': 200, 'HTTPHeaders': {'content-type': 'application/json', 'content-length': ...}, 'RetryAttempts': 0}, 'apps': [{'appId': 'dym7444jed2kq', 'appArn': 'arn:aws:amplify:us-east-2:763175725735:apps/dym7444jed2kq', 'name': 'vesting-interface', 'tags': {}, 'repository': 'https://github.com/...interface', 'platform': 'WEB', 'createTime': datetime.datetime(2021, 5, 4, 3, 41, 34, 717000, tzinfo=tzlocal()), 'updateTime': datetime.datetime(2021, 5, 4, 3, 41, 34, 717000, tzinfo=tzlocal()), 'environmentVariables': {}, 'defaultDomain': 'dym7444jed2kq.amplifyapp.com', 'customRules': _rules_, 'productionBranch': {'lastDeployTime': datetime.datetime(2021, 5, 26, 15, 10, 7, 694000, tzinfo=tzlocal()), 'status': 'SUCCEED', 'thumbnailUrl': 'https://aws-amplify-', 'branchName': 'main'},     - yarn install\n    build:\n      commands:\n        - yarn run build\n  artifacts:\n    baseDirectory: build\n    files:\n      - '**/*'\n  cache:\n    paths:\n      - node_modules/**/*\n", 'customHeaders': '', 'enableAutoBranchCreation': False}]}
---------------

我很困惑,为什么下一次迭代没有nextToken,我怎样才能得到下一个appId。

【问题讨论】:

    标签: aws-lambda boto3 aws-amplify amplify aws-amplify-cli


    【解决方案1】:
    import boto3
    import json
    session=boto3.session.Session(profile_name='<Profile_Name>')
    amplify_client=session.client('amplify',region_name='ap-south-1')
    output=amplify_client.list_apps()
    print(output['apps'])
    

    【讨论】:

    • # 请输入您要使用的 例如使用 "aws configure --profile=" 配置的 root 或开发人员#
    • 我的问题是,当我打印 output['apps'] 时,我只得到第一个条目而不是所有条目,这就是为什么我试图找出如何正确使用 nextToken 或分页技术。
    • 我认为您在本地运行 boto3 而不是 lambda,也许这就是您获得预期输出的原因。
    • 虽然此代码可能会为问题提供解决方案,但最好添加有关其工作原理/方式的上下文。这可以帮助未来的用户学习并将这些知识应用到他们自己的代码中。在解释代码时,您也可能会以赞成票的形式从用户那里获得积极的反馈。
    • edit而不是评论更新。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-21
    • 1970-01-01
    相关资源
    最近更新 更多