问题
Where do I retrieve the NextToken from when using the AWS Powershell CmdLets?
For example when I call Get-CDDeploymentList I need to supply the NextToken to retrieve the next set of deployment IDs. However the Get-CDDeploymentList command only returns an array of deployment IDs and not a NextToken.
回答1:
The NextToken is contained in the $AWSHistory.LastServiceResponse variable.
In the case of the Get-CDDeploymentList
command the LastServiceResponse will contain the properties Deployments
and the NextToken
, so the NextToken can be retrieved using:
$AWSHistory.LastServiceResponse.NextToken
For more information on the $AWSHistory object see http://docs.aws.amazon.com/powershell/latest/userguide/pstools-pipelines.html.
回答2:
Actually you don't need to use NextToken unless you want or need to take manual control of pagination. By default, if NextToken isn't supplied to the vast majority of the cmdlets, they will automatically handle pagination for you internally and make multiple calls to the underlying service api to emit the full data set to the pipeline.
There are a couple of service apis where the response data from the api call contains more than one field that we would emit to the pipeline (imagine a call that returned a list of 'success' elements as well as a list of 'failed' elements). In these scenarios the cmdlets will emit the entire response object to the pipeline and it will contain the next token element -- for these you (the user) have to manually paginate.
I'm sure we used to note when cmdlets auto-paginate (and when they don't) in the cmdlet documentation but in looking at the linked cmdlet documentation it seems we've dropped this somewhere along the way - I'll investigate and get this fixed.
来源:https://stackoverflow.com/questions/37571134/aws-powershell-how-do-i-retrieve-the-nexttoken