Issue with AWS S3 SDK on CloudFlare Pages

Hi all,

I’m creating a website using SvelteKit, which I’m deploying on Cloudflare Pages using the Cloudflare Pages adapter. The site has to fetch some objects from AWS S3, the logic for which runs successfully on the server.

However, I am having issues using AWS S3 Multi-Region Access Points (MRAP) which I believe is a Cloudflare Pages issue, not an S3 SDK issue.

I am using the AWS S3 SDK - as per my package.json:

"dependencies": {
	"@aws-sdk/client-s3": "^3.241.0",
	"@aws-sdk/signature-v4-crt": "^3.226.0"
}

Here is the (reduced) server code, found in +server.ts:

import {
  S3Client,
  GetObjectCommand,
  ListObjectVersionsCommand
} from '@aws-sdk/client-s3';

const BUCKET = 'my-bucket';

/// This object is used to send requests to the AWS SDK
const client = new S3Client({
	region: 'eu-west-1',
	disableMultiregionAccessPoints: false,
	credentials: {
		accessKeyId: 'REDACTED',
		secretAccessKey: 'REDACTED'
	}
});

/// Fetched the blog with unique 
async function s3_load_blog() {
	let html = '';

	try {
		const get_obj = new GetObjectCommand({
			Bucket: BUCKET,
			Key: 'blogs/my-first-blog.html'
		});

		const { Body } = await client.send(get_obj);
		let promise = new Response(Body as ReadableStream, {}).text();
		await promise.then(async (res) => {
			html += await res;
		});
		return html;
	} catch (error) {
		console.error(error);
		html += `<h5>${error}</h5>`;
		return html;
	}
}

This fundamental logic will succesfully fetch a file stored as an S3 object and read its contents into a string. Some additional code will render this on screen. I can wrap it in a GET function to create an API for it.

I would like my site to be fast across multiple regions - using AWS S3 MRAP, I can create duplicate buckets in multiple regions, make a request to the MRAP endpoint, and it will select the closest bucket to the caller. Great. I just change one line:

const BUCKET = 'arn:aws:s3::123456789012:accesspoint/my_mrap.mrap';

This change works, and is noticeably faster, when I run using vite dev or vite build; vite preview on my local machine. I can even see in my AWS dashboard the MRAP usage goes up.

However, when deployed onto Cloudflare pages, the fetching code fails. You can’t view server logs on Cloudflare Pages, but altering my code so that it renders the error on rendered webpage, I get this:

Error: This request requires signing with SigV4Asymmetric algorithm. It's only available in Node.js

The only similar GitHub issue I can find is this - https://github.com/aws/aws-sdk-js/issues/3894 - but I’m not convinced they’re too alike.

I would assume this is an issue with the SDK itself, except that the exact same code does work on my local machine, even when built using the same build instruction.

Any advice or insight would be appreciated :heart:

You can read more about MRAP here https://docs.aws.amazon.com/AmazonS3/latest/userguide/MultiRegionAccessPoints.html