From f220e853c4ab2cbabba4dc616790d98ac104d4e4 Mon Sep 17 00:00:00 2001 From: Vale Bedu <7014514+valebedu@users.noreply.github.com> Date: Fri, 6 Oct 2023 12:06:46 +0200 Subject: [PATCH] fix(type-safe-api): replace stack partition/region by bucket ones to construct bucket invocation URI --- .../type-safe-api/src/construct/integrations/s3.ts | 6 +----- packages/type-safe-api/src/construct/spec/utils.ts | 12 ++++-------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/packages/type-safe-api/src/construct/integrations/s3.ts b/packages/type-safe-api/src/construct/integrations/s3.ts index 4c4f92170..9229d90e7 100644 --- a/packages/type-safe-api/src/construct/integrations/s3.ts +++ b/packages/type-safe-api/src/construct/integrations/s3.ts @@ -62,11 +62,7 @@ export class S3Integration extends Integration { return { type: "AWS", httpMethod: props.method.toUpperCase(), - uri: bucketInvocationUri( - props.scope, - this.bucket, - this.pathOverride ?? props.path - ), + uri: bucketInvocationUri(this.bucket, this.pathOverride ?? props.path), credentials: this.role.roleArn, responses: { default: { diff --git a/packages/type-safe-api/src/construct/spec/utils.ts b/packages/type-safe-api/src/construct/spec/utils.ts index d36031dbc..d6e0abfbc 100644 --- a/packages/type-safe-api/src/construct/spec/utils.ts +++ b/packages/type-safe-api/src/construct/spec/utils.ts @@ -20,16 +20,12 @@ export const functionInvocationUri = ( /** * Generate the s3 bucket invocation uri for the given s3 within the given scope - * @param scope scope in which the s3 is deployed * @param bucket the s3 bucket to be invoked + * @param path? the path to object to invoke, default to none */ -export const bucketInvocationUri = ( - scope: Construct, - bucket: IBucket, - pathOverride?: string -): string => { - const stack = Stack.of(scope); +export const bucketInvocationUri = (bucket: IBucket, path?: string): string => { + const stack = bucket.stack; return `arn:${stack.partition}:apigateway:${stack.region}:s3:path/${ bucket.bucketName - }/${pathOverride ?? ""}`; + }/${path ?? ""}`; };