awslabs / aws-sdk-rust

AWS SDK for the Rust Programming Language
https://awslabs.github.io/aws-sdk-rust/
Apache License 2.0
3.04k stars 247 forks source link

[request]: Implement paginator for DescribeRules in aws-sdk-elasticloadbalancingv2 #447

Open coord-e opened 2 years ago

coord-e commented 2 years ago

A note for the community

Community Note

Tell us about your request

Paginator for DescribeRules in aws-sdk-elasticloadbalancingv2.

Tell us about the problem you're trying to solve.

I want to describe all rules for a listener by listener's ARN. DescribeRules operation has an interface for pagination (marker, next_marker, etc.) and I have to use them to list up all rules for a listener. Some operations in aws-sdk-elasticloadbalancingv2 has paginator implementations so they can be paginated easily, but DescribeRules does not. Having paginator for DescribeRules would be nice.

Are you currently working around this issue?

Implements pagination manually. Note that the following code is for v0.3.0.

client
  .describe_rules()
  .listener_arn(listener_arn.clone())
  .send()
  .and_then(move |output| async move {
      let next_marker = output.next_marker.clone();
      let head = futures::stream::once(async { Ok(output) });
      let tail = futures::stream::try_unfold(next_marker, move |next_marker| {
          let listener_arn = listener_arn.clone();
          async move {
              let next_marker = match next_marker {
                  Some(marker) if !marker.is_empty() => marker,
                  _ => return Ok(None),
              };

              let output = elbv2
                  .describe_rules()
                  .marker(next_marker)
                  .listener_arn(listener_arn.clone())
                  .send()
                  .await?;
              let next_marker = output.next_marker.clone();
              Ok(Some((output, next_marker)))
          }
      });
      Ok(head.chain(tail))
  })
  .try_flatten_stream()

Additional context

No response

rcoh commented 2 years ago

Thanks for pointing this out. I've forwarded this request to the AWS team that maintains that model and will follow up here with any updates. By the way, that's a super clever way of implementing a paginator, I never considered chaining streams together like that!