From c73aeeec3d296b3a6e203eba4513f6bd4bb65732 Mon Sep 17 00:00:00 2001 From: Michael Kret <88898367+michael-radency@users.noreply.github.com> Date: Fri, 16 Feb 2024 15:13:26 +0200 Subject: [PATCH] fix(AwsS3 Node): Use location constrain (#8654) --- packages/nodes-base/credentials/Aws.credentials.ts | 10 ++++++++-- .../nodes-base/nodes/Aws/S3/V2/GenericFunctions.ts | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/nodes-base/credentials/Aws.credentials.ts b/packages/nodes-base/credentials/Aws.credentials.ts index 23171f742f..3b52e47d23 100644 --- a/packages/nodes-base/credentials/Aws.credentials.ts +++ b/packages/nodes-base/credentials/Aws.credentials.ts @@ -284,7 +284,13 @@ export class Aws implements ICredentialType { let path = requestOptions.qs?.path; const method = requestOptions.method; let body = requestOptions.body; + let region = credentials.region; + if (requestOptions.qs?._region) { + region = requestOptions.qs._region as string; + delete requestOptions.qs._region; + } + let query = requestOptions.qs?.query as IDataObject; // ! Workaround as we still use the IRequestOptions interface which uses uri instead of url // ! To change when we replace the interface with IHttpRequestOptions @@ -324,10 +330,10 @@ export class Aws implements ICredentialType { } else if (service === 'sqs' && credentials.sqsEndpoint) { endpointString = credentials.sqsEndpoint as string; } else if (service) { - endpointString = `https://${service}.${credentials.region}.amazonaws.com`; + endpointString = `https://${service}.${region}.amazonaws.com`; } endpoint = new URL( - endpointString!.replace('{region}', credentials.region as string) + (path as string), + endpointString!.replace('{region}', region as string) + (path as string), ); } else { // If no endpoint is set, we try to decompose the path and use the default endpoint diff --git a/packages/nodes-base/nodes/Aws/S3/V2/GenericFunctions.ts b/packages/nodes-base/nodes/Aws/S3/V2/GenericFunctions.ts index 1ad21232d8..c4e47a8af3 100644 --- a/packages/nodes-base/nodes/Aws/S3/V2/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Aws/S3/V2/GenericFunctions.ts @@ -29,12 +29,14 @@ export async function awsApiRequest( service, path, query, + _region, }, method, body, url: '', headers, } as IHttpRequestOptions; + if (Object.keys(option).length !== 0) { Object.assign(requestOptions, option); }