简体   繁体   中英

AWS boto3 list codepipelines

I am trying to list all the pipelines on AWS, and am passing nextToken as session token. However this does not seem to work, any ideas?

import boto3


def list_pipelines():
    session = boto3.Session(
        aws_access_key_id="AKIAJMO63R4OAY6HMXUQ",
        aws_secret_access_key="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"
    )
    credentials = session.get_credentials()
    print credentials
    code_pipeline = boto3.client('codepipeline')
    pipelines = code_pipeline.list_pipelines(nextToken=credentials.token)
    for i in pipelines:
        print i


def main():
    list_pipelines()

if __name__ == "__main__":
    main()

OUTPUT:

botocore.exceptions.ParamValidationError: Parameter validation failed:
Invalid type for parameter nextToken, value: None, type: <type 'NoneType'>, valid types: <type 'basestring'>

You misinterpreted the meaning of nextToken . It is used for pagination. The first time, you call without the nextToken parameter. If the response has hasMoreResults set to True , then in the next call use the marker returned in the response to the previous call.

  while pipelines['hasMoreResults']:
    pipelines = code_pipeline.list_pipelines(nextToken=pipelines['marker'])

List Pipelines

Request Syntax

response = client.list_pipelines(
    marker='string'
)

Parameters

marker (string) -- The starting point for the results to be returned. For the first call, this value should be empty. As long as there are more results, continue to call ListPipelines with the marker value from the previous call to retrieve the next set of results.

Response Syntax

{
    'pipelineIdList': [
        {
            'id': 'string',
            'name': 'string'
        },
    ],
    'marker': 'string',
    'hasMoreResults': True|False
}

marker (string)

The starting point for the next page of results. To view the next page of results, call ListPipelinesOutput again with this marker value. If the value is null, there are no more results.

hasMoreResults (boolean)

Indicates whether there are more results that can be obtained by a subsequent call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM