fix: treat any url ending with amazonaws.com or amazonaws.com.cn as Amazon hosted

Signed-off-by: Travis O'Neal <wtravisoneal@gmail.com>
This commit is contained in:
Travis O'Neal
2026-03-26 22:09:15 -04:00
parent 66a75bd7d5
commit 6e2aaabdf3
3 changed files with 58 additions and 1 deletions
@@ -0,0 +1,5 @@
---
'@backstage/backend-defaults': patch
---
Fixed `AwsS3UrlReader` failing to read files from S3 buckets configured with custom endpoint hosts. When an integration was configured with a specific endpoint like `https://bucket-1.s3.eu-central-1.amazonaws.com`, the URL parser incorrectly fell through to the non-AWS code path, always defaulting the region to `us-east-1` instead of extracting it from the hostname.
@@ -128,6 +128,55 @@ describe('parseUrl', () => {
});
});
it('supports aws formats with custom endpoint hosts', () => {
expect(
parseUrl(
'https://bucket-1.s3.eu-central-1.amazonaws.com/path/to/file.yaml',
{
host: 'bucket-1.s3.eu-central-1.amazonaws.com',
},
),
).toEqual({
path: 'path/to/file.yaml',
bucket: 'bucket-1',
region: 'eu-central-1',
});
expect(
parseUrl('https://my-bucket.s3.cn-north-1.amazonaws.com.cn/data.json', {
host: 'my-bucket.s3.cn-north-1.amazonaws.com.cn',
}),
).toEqual({
path: 'data.json',
bucket: 'my-bucket',
region: 'cn-north-1',
});
expect(
parseUrl(
'https://s3.eu-central-1.amazonaws.com/my-bucket/path/to/file.yaml',
{
host: 's3.eu-central-1.amazonaws.com',
},
),
).toEqual({
path: 'path/to/file.yaml',
bucket: 'my-bucket',
region: 'eu-central-1',
});
expect(
parseUrl(
'https://s3.eu-central-1.amazonaws.com/my-bucket/path/to/file.yaml',
{
host: 's3.eu-central-1.amazonaws.com',
s3ForcePathStyle: true,
},
),
).toEqual({
path: 'path/to/file.yaml',
bucket: 'my-bucket',
region: 'eu-central-1',
});
});
it('supports all non-aws formats', () => {
expect(
parseUrl('https://my-host.com/my.bucket-3/a/puppy.jpg', {
@@ -74,7 +74,10 @@ export function parseUrl(
const host = parsedUrl.host;
// Treat Amazon hosted separately because it has special region logic
if (config.host === 'amazonaws.com' || config.host === 'amazonaws.com.cn') {
if (
config.host.endsWith('amazonaws.com') ||
config.host.endsWith('amazonaws.com.cn')
) {
const match = host.match(
/^(?:([a-z0-9.-]+)\.)?s3(?:[.-]([a-z0-9-]+))?\.amazonaws\.com(\.cn)?$/,
);