I have a piece of python code that calls the ListStacks action on AWS's Cloudformation API:
client = boto3.client('cloudformation', region_name='[MYREGION]')
status_filter = ['CREATE_COMPLETE', 'UPDATE_COMPLETE', 'ROLLBACK_COMPLETE']
response = client.list_stacks(StackStatusFilter=status_filter)
next_token = response.get('NextToken', None)
while next_token:
response = client.list_stacks(NextToken=next_token)
On the last line, it throws a ValidationError:
An error occurred (ValidationError) when calling the ListStacks operation: [TOKEN] is not a valid NextToken
This has been working fine for month, but now it suddenly throws this error. There has been no changes to the code.
Curiously, the response is smaller than 1MB, so the token should be null, according to the documentation:
NextToken
If the output exceeds 1 MB in size, a string that identifies the next page of stacks.
If no additional page exists, this value is null.
Type: String
Length Constraints: Minimum length of 1. Maximum length of 1024
Does anyone have an idea why the response contains an (invalid) NextToken rather than null?
Edit
My assumption that the response was not exceeding the limit was wrong. It did only return a subset of the stacks fitting the filter.
So the question is rather: Why is the NextToken invalid?