Implement idempotency for Spot instance requests

I am using the Java AWS SDK to create EC2 instance requests. Unlike on demand instances, the point request API has nothing like ClientToken and therefore does not support idempotency out of the box.

The easiest way I could come up with is to set the LaunchGroup property to a unique UUID; when I check this, I call DescribeSpotInstanceRequests and see if I already have a request with the same launch group.

To my surprise, it seems that the delay before calling the description returns requests to the place sent earlier. I wrote a JUnit test for this, and it seems that in order for it to be consistent, I would have to set a timeout of at least 60 seconds between two calls (an instance of a place request and describe requests for a place instance). I need to have a dimension of 10 seconds, because my requests can be repeated by the application at this interval, in case of any failure - that is, something breaks after I sent the request, but before I could read the result, I returned from Amazon In this case, I do not want to repeat the request, I just want it to register and go.

 @Test public void testRunSpotInstances() throws Exception { activity.execute(execution); timeout(TIMEOUT); // shouldn't do anything activity.execute(execution); timeout(TIMEOUT); DescribeSpotInstanceRequestsResult result = client.describeSpotInstanceRequests( new DescribeSpotInstanceRequestsRequest().withFilters(new Filter() .withName("launch-group").withValues(BUSINESS_KEY))); assertThat(result.getSpotInstanceRequests()).hasSize(1); timeout(TIMEOUT); } 

The test runs every time if TIMEOUT is set to 60 seconds; for the 40-50s, he works intermittently. Anything below this fails every time.

Could anyone get around this delay? Is idempotency implementation for point requests possible using only the AWS API and no state stored in the client application?

+6
source share
1 answer

In this case, I do not want to repeat the request, I just want it to register and move on.

If you received 200 back, then it is registered. It may not be displayed immediately, but it is registered, and you can move in your stream.

Is idempotency implementation for point requests possible using only the AWS API and not preserving state in the client application?

I donโ€™t believe that. I have the same problem with Amazon EMR. The way I work is to have a component that should monitor the clusters. When I make a request for an EMR cluster, I return the cluster identifier, which I then pass to some observer. Then the observer will call my other components when this cluster changes state. An unconfirmed EMR is immediately valid and is not considered an exception.

I have no idea if this is right for you. Perhaps you could try saving SpotInstanceRequestId . In my case, I only store them in memory, but if necessary, you can keep them persistent somewhere.

0
source

All Articles