I have the following API call
cloudwatchClient.deleteInsightRules(
new DeleteInsightRulesRequest().withRuleNames(existingRuleNames));
which fails because
[exec] Exception in thread "main" com.amazonaws.services.cloudwatch.model.MissingRequiredParameterException: BATCH_REQUEST_TOO_LARGE: Batch size cannot exceed 20 items. (Service: AmazonCloudWatch; Status Code: 400; Error Code: MissingRequiredParameterException; Request ID: 0f820dc2-38b8-11e9-8465-3718764429f1)
Now I understand that I have to make multiple calls to deleteInsight rules for cloudwatch in chunks of 20.
So conceptually I am looking for
existingRuleNames
.stream().
.chunkIntoSizeOf(20) // This is an imaginary method, i need to convert it into something concrete
.foreach(chunk -> cloudwatchClient.deleteInsightRules(
new DeleteInsightRulesRequest().withRuleNames(chunk));
Now I cant find anything in the java 8 streams api that allows me to divide and process my lists into chunks. Kind of like the scala grouped functionality Split list into multiple lists with fixed number of elements.
Can anyone help me out with this? Thanks. I can of course use an imperative style and use sublists, but I prefer to avoid that if I can.