T
TanStack3y ago
fascinating-indigo

Can you cancel requests from the AWS-SDK?

I want to create a query via the aws-sdk. My code currently looks something like this:
import { useInfiniteQuery } from "@tanstack/react-query";
import { S3 } from "@aws-sdk/client-s3";

const client = new S3(config);

function FileList({ Bucket }) {
const { data, isLoading } = useInfiniteQuery({
queryKey: ["files"],
queryFn: async ({ pageParam }) => {
return client.ListBuckets({ marker: pageParam, Bucket });
}
});
}
import { useInfiniteQuery } from "@tanstack/react-query";
import { S3 } from "@aws-sdk/client-s3";

const client = new S3(config);

function FileList({ Bucket }) {
const { data, isLoading } = useInfiniteQuery({
queryKey: ["files"],
queryFn: async ({ pageParam }) => {
return client.ListBuckets({ marker: pageParam, Bucket });
}
});
}
I need to extend the queryFn to cancel this request if possible, but I'm not sure how this is done with the AWS-SDK, has anyone worked with this before?
1 Reply
wise-white
wise-white3y ago
If the SDK accepts an abort controller signal then you could use that. Failing that, you can cancel the query via React Query, but it won't actually cancel the in-flight request: https://tanstack.com/query/v4/docs/react/guides/query-cancellation#manual-cancellation

Did you find this page helpful?