Skip to content

Commit

Permalink
s3 template update
Browse files Browse the repository at this point in the history
  • Loading branch information
rjjaegeraws committed Mar 12, 2024
1 parent b31529a commit 719c347
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/lib/cdk-constructs/src/firewall/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/lib/custom-resources/cdk-s3-template/cdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const resourceType = 'Custom::S3Template';
export interface S3TemplateProps {
templateBucket: s3.IBucket;
templatePath: string;
templateBucketRegion: string;
outputBucket: s3.IBucket;
outputPath: string;
}
Expand All @@ -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: {},
Expand Down
8 changes: 6 additions & 2 deletions src/lib/custom-resources/cdk-s3-template/runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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...`);
Expand All @@ -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
Expand Down

0 comments on commit 719c347

Please sign in to comment.