0

I have a lot of amplify apps which I want to manage via Lambdas. What is the equivalent of the cli command aws amplify list-apps in boto3, I had multiple attempts, but none worked out for me. My bit of code that was using nextToken looked like this:

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('=================')

Then I tried to use paginators like:

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

for i in response_iterator:
    print(i)

Both of the attempts were throwing inconsistent output. The first one was printing first token and second entry but nothing more. The second one gives only the first entry.

Edit with more attemptsinfo + output. Bellow piece of code:

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}]}
---------------

I am very confused, why next iteration doesn't has nextToken and how can I get to the next appId.

kraken
  • 19
  • 2

1 Answers1

0
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'])
Anurag Arya
  • 111
  • 4
  • # Please enter the which you want to use e.g. root or developers # which configured using "aws configure --profile=" – Anurag Arya Oct 19 '21 at 14:40
  • My problem is that when I print output['apps'] I am getting only the first entry and not all of them that is why I am trying to find out how to use correctly `nextToken` or pagination technics. – kraken Oct 19 '21 at 14:52
  • I presume that you are running boto3 on your local, instead of lambda, maybe that is why you are getting expected output. – kraken Oct 19 '21 at 14:53
  • 1
    While this code may provide a solution to the question, it's better to add context as to why/how it works. This can help future users learn, and apply that knowledge to their own code. You are also likely to have positive feedback from users in the form of upvotes, when the code is explained. – borchvm Oct 20 '21 at 05:43
  • Please [edit] instead of commenting to update. – General Grievance Oct 20 '21 at 12:12
  • I have edited original post with some relevant output. – kraken Oct 20 '21 at 14:46