botocore.exceptions.WaiterError: Waiter StackCreateComplete failed: Max attempts exceeded

Question:

I am getting above error when running a python code with boto3. It is erroring out at 1 hour all the time and the stack is being created even after this error. I have applied both MaxSessionDuration of the IAM role and the duration_seconds configuration value of the AWS CLI but did not helped. Also I bumped the CreationPolicyTimer to 12H so the stack creation is taking that much time but it is errroring out in the aws cli after running it for an hour. Seems like some default for either aws cli or linux cli which times out after an hour and giving error as below while creating a cloudformation stack via aws cli.

 File "/usr/local/lib/python3.8/dist-packages/botocore/waiter.py", line 54, in wait
18:58:53      Waiter.wait(self, **kwargs)
18:58:53    File "/usr/local/lib/python3.8/dist-packages/botocore/waiter.py", line 363, in wait
18:58:53      raise WaiterError(
18:58:53  botocore.exceptions.WaiterError: Waiter StackCreateComplete failed: Max attempts exceeded

Also I am running this inside a docker container in a jenkins agent.

Asked By: 10raw

||

Answers:

for a waiter in the line
waiter.wait(StackName=name), adding the code from below did the trick.
here is the documentation
https://boto3.amazonaws.com/v1/documentation/api/1.9.42/reference/services/cloudformation.html#CloudFormation.Waiter.ChangeSetCreateComplete.wait
you can set and test with the waiterconfig, for example

waiter.wait(
    StackName=name,
    WaiterConfig={
        'Delay': 123,
        'MaxAttempts': 123
    }
)
Answered By: 10raw