diff --git a/moto/cloudformation/responses.py b/moto/cloudformation/responses.py index 06d0bbb00..695118319 100644 --- a/moto/cloudformation/responses.py +++ b/moto/cloudformation/responses.py @@ -292,7 +292,7 @@ DESCRIBE_STACK_RESOURCES_RESPONSE = """ DESCRIBE_STACK_EVENTS_RESPONSE = """ - {% for event in stack.events %} + {% for event in stack.events[::-1] %} {{ event.timestamp.strftime('%Y-%m-%dT%H:%M:%S.%fZ') }} {{ event.resource_status }} diff --git a/tests/test_cloudformation/test_cloudformation_stack_crud.py b/tests/test_cloudformation/test_cloudformation_stack_crud.py index e145ea283..7eb563c42 100644 --- a/tests/test_cloudformation/test_cloudformation_stack_crud.py +++ b/tests/test_cloudformation/test_cloudformation_stack_crud.py @@ -509,10 +509,15 @@ def test_describe_stack_events_shows_create_update_and_delete(): events[-1].resource_type.should.equal("AWS::CloudFormation::Stack") # testing ordering of stack events without assuming resource events will not exist + # the AWS API returns events in reverse chronological order stack_events_to_look_for = iter([ - ("CREATE_IN_PROGRESS", "User Initiated"), ("CREATE_COMPLETE", None), - ("UPDATE_IN_PROGRESS", "User Initiated"), ("UPDATE_COMPLETE", None), - ("DELETE_IN_PROGRESS", "User Initiated"), ("DELETE_COMPLETE", None)]) + ("DELETE_COMPLETE", None), + ("DELETE_IN_PROGRESS", "User Initiated"), + ("UPDATE_COMPLETE", None), + ("UPDATE_IN_PROGRESS", "User Initiated"), + ("CREATE_COMPLETE", None), + ("CREATE_IN_PROGRESS", "User Initiated"), + ]) try: for event in events: event.stack_id.should.equal(stack_id) diff --git a/tests/test_cloudformation/test_cloudformation_stack_crud_boto3.py b/tests/test_cloudformation/test_cloudformation_stack_crud_boto3.py index 97c3e864a..98ed213e5 100644 --- a/tests/test_cloudformation/test_cloudformation_stack_crud_boto3.py +++ b/tests/test_cloudformation/test_cloudformation_stack_crud_boto3.py @@ -345,10 +345,15 @@ def test_stack_events(): events[-1].resource_type.should.equal("AWS::CloudFormation::Stack") # testing ordering of stack events without assuming resource events will not exist + # the AWS API returns events in reverse chronological order stack_events_to_look_for = iter([ - ("CREATE_IN_PROGRESS", "User Initiated"), ("CREATE_COMPLETE", None), - ("UPDATE_IN_PROGRESS", "User Initiated"), ("UPDATE_COMPLETE", None), - ("DELETE_IN_PROGRESS", "User Initiated"), ("DELETE_COMPLETE", None)]) + ("DELETE_COMPLETE", None), + ("DELETE_IN_PROGRESS", "User Initiated"), + ("UPDATE_COMPLETE", None), + ("UPDATE_IN_PROGRESS", "User Initiated"), + ("CREATE_COMPLETE", None), + ("CREATE_IN_PROGRESS", "User Initiated"), + ]) try: for event in events: event.stack_id.should.equal(stack.stack_id)