1

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.

Castrohenge
  • 8,525
  • 5
  • 39
  • 66

2 Answers2

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.

Castrohenge
  • 8,525
  • 5
  • 39
  • 66
1

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.

Steve Roberts
  • 714
  • 4
  • 8
  • If you could get the Get-CDDeploymentList to return all Ids that would be great, thanks! :) – Castrohenge Jun 01 '16 at 16:21
  • 2
    My response was going to be 'it already does' but when I checked the code it looks like none of the CodeDeploy cmdlets got generated with auto-pagination support. So yes, I'll fix it in the next day or so. – Steve Roberts Jun 01 '16 at 16:41
  • 1
    Version 3.1.74.0 has just been released that extends auto-pagination to the CodeDeploy cmdlets. The documentation for the cmdlets has also been extended to note those cmdlets that auto-paginate (the web version of these docs is currently still rolling out). – Steve Roberts Jun 03 '16 at 23:44