Save EC2 cloud when error code is ExpiredToken
#1084
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR enhances the handling of

ExpiredToken
error code for theAwsServiceException
exception in theprovision
method ofEC2Cloud
. The previous PR #1008 successfully catches the exception error code, but thereconnectToEc2()
call doesn't resolve the issue, and the AWS STS token remains expired. Our investigation revealed that saving the EC2 Cloud configuration refreshes the AWS STS token and resolves the problem. Currently, we're mitigating this by manually saving configurationsor running the Groovy script below via the Script Console.
The script above performs the save on all the EC2 Clouds and changes the session name to validate that a change/save has been made on each cloud. However, saving the cloud without changing fields is enough to handle the issue. This PR automates this process to eliminate the need for external intervention and save the EC2 Cloud configuration only if and when necessary.
Testing done
We've been experiencing this issue in our production and testing environments, but couldn't reliably reproduce it.
To validate the solution:
ExpiredToken
issueThe fix handles the token refresh transparently to users, maintaining the same behaviour but eliminating the need for external configuration saves.
Submitter checklist