From 719c347095439cf67cb8e56e495a926134993d54 Mon Sep 17 00:00:00 2001 From: Ryan Jaeger Date: Tue, 12 Mar 2024 13:39:49 -0700 Subject: [PATCH] s3 template update --- src/lib/cdk-constructs/src/firewall/instance.ts | 2 ++ src/lib/custom-resources/cdk-s3-template/cdk/index.ts | 2 ++ .../custom-resources/cdk-s3-template/runtime/src/index.ts | 8 ++++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/lib/cdk-constructs/src/firewall/instance.ts b/src/lib/cdk-constructs/src/firewall/instance.ts index 8ce259c72..4f228d629 100644 --- a/src/lib/cdk-constructs/src/firewall/instance.ts +++ b/src/lib/cdk-constructs/src/firewall/instance.ts @@ -84,6 +84,7 @@ export class FirewallInstance extends Construct { if (props.licenseBucket && props.licensePath) { new S3Template(this, 'License', { templateBucket: props.licenseBucket, + templateBucketRegion: configuration.bucketRegion, templatePath: props.licensePath, outputBucket: configuration.bucket, outputPath: props.licensePath, @@ -93,6 +94,7 @@ export class FirewallInstance extends Construct { if (configuration.templateConfigPath) { this.template = new S3Template(this, 'Config', { templateBucket: configuration.templateBucket, + templateBucketRegion: configuration.bucketRegion, templatePath: configuration.templateConfigPath, outputBucket: configuration.bucket, outputPath: configuration.configPath, diff --git a/src/lib/custom-resources/cdk-s3-template/cdk/index.ts b/src/lib/custom-resources/cdk-s3-template/cdk/index.ts index e39cb1192..5f1d96624 100644 --- a/src/lib/custom-resources/cdk-s3-template/cdk/index.ts +++ b/src/lib/custom-resources/cdk-s3-template/cdk/index.ts @@ -24,6 +24,7 @@ const resourceType = 'Custom::S3Template'; export interface S3TemplateProps { templateBucket: s3.IBucket; templatePath: string; + templateBucketRegion: string; outputBucket: s3.IBucket; outputPath: string; } @@ -40,6 +41,7 @@ export class S3Template extends Construct { this.handlerProperties = { templateBucketName: props.templateBucket.bucketName, templatePath: props.templatePath, + templateBucketRegion: props.templateBucketRegion, outputBucketName: props.outputBucket.bucketName, outputPath: props.outputPath, parameters: {}, diff --git a/src/lib/custom-resources/cdk-s3-template/runtime/src/index.ts b/src/lib/custom-resources/cdk-s3-template/runtime/src/index.ts index 98b3371b2..1c7c23763 100644 --- a/src/lib/custom-resources/cdk-s3-template/runtime/src/index.ts +++ b/src/lib/custom-resources/cdk-s3-template/runtime/src/index.ts @@ -22,12 +22,13 @@ export type TemplateParameters = { [key: string]: string }; export interface HandlerProperties { templateBucketName: string; templatePath: string; + templateBucketRegion: string; outputBucketName: string; outputPath: string; parameters: TemplateParameters; } -const s3 = new AWS.S3(); +let s3 = new AWS.S3(); async function onEvent(event: CloudFormationCustomResourceEvent) { console.log(`Creating S3 object from template...`); @@ -48,11 +49,14 @@ export const handler = errorHandler(onEvent); async function onCreate(event: CloudFormationCustomResourceEvent) { const properties = (event.ResourceProperties as unknown) as HandlerProperties; - const { templateBucketName, templatePath, outputBucketName, outputPath } = properties; + const { templateBucketName, templatePath, templateBucketRegion, outputBucketName, outputPath } = properties; // Load template console.debug(`Loading template ${templateBucketName}/${templatePath}`); let bodyString; + + s3 = templateBucketRegion ? new AWS.S3({ region: templateBucketRegion }) : s3; + try { const object = await throttlingBackOff(() => s3