Skip to content

Commit b59818b

Browse files
authored
s3 template update (#1221)
1 parent 2102ceb commit b59818b

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

src/lib/cdk-constructs/src/firewall/instance.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export class FirewallInstance extends Construct {
8484
if (props.licenseBucket && props.licensePath) {
8585
new S3Template(this, 'License', {
8686
templateBucket: props.licenseBucket,
87+
templateBucketRegion: configuration.bucketRegion,
8788
templatePath: props.licensePath,
8889
outputBucket: configuration.bucket,
8990
outputPath: props.licensePath,
@@ -93,6 +94,7 @@ export class FirewallInstance extends Construct {
9394
if (configuration.templateConfigPath) {
9495
this.template = new S3Template(this, 'Config', {
9596
templateBucket: configuration.templateBucket,
97+
templateBucketRegion: configuration.bucketRegion,
9698
templatePath: configuration.templateConfigPath,
9799
outputBucket: configuration.bucket,
98100
outputPath: configuration.configPath,

src/lib/custom-resources/cdk-s3-template/cdk/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const resourceType = 'Custom::S3Template';
2424
export interface S3TemplateProps {
2525
templateBucket: s3.IBucket;
2626
templatePath: string;
27+
templateBucketRegion: string;
2728
outputBucket: s3.IBucket;
2829
outputPath: string;
2930
}
@@ -40,6 +41,7 @@ export class S3Template extends Construct {
4041
this.handlerProperties = {
4142
templateBucketName: props.templateBucket.bucketName,
4243
templatePath: props.templatePath,
44+
templateBucketRegion: props.templateBucketRegion,
4345
outputBucketName: props.outputBucket.bucketName,
4446
outputPath: props.outputPath,
4547
parameters: {},

src/lib/custom-resources/cdk-s3-template/runtime/src/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ export type TemplateParameters = { [key: string]: string };
2222
export interface HandlerProperties {
2323
templateBucketName: string;
2424
templatePath: string;
25+
templateBucketRegion: string;
2526
outputBucketName: string;
2627
outputPath: string;
2728
parameters: TemplateParameters;
2829
}
2930

30-
const s3 = new AWS.S3();
31+
let s3 = new AWS.S3();
3132

3233
async function onEvent(event: CloudFormationCustomResourceEvent) {
3334
console.log(`Creating S3 object from template...`);
@@ -48,11 +49,14 @@ export const handler = errorHandler(onEvent);
4849

4950
async function onCreate(event: CloudFormationCustomResourceEvent) {
5051
const properties = (event.ResourceProperties as unknown) as HandlerProperties;
51-
const { templateBucketName, templatePath, outputBucketName, outputPath } = properties;
52+
const { templateBucketName, templatePath, templateBucketRegion, outputBucketName, outputPath } = properties;
5253

5354
// Load template
5455
console.debug(`Loading template ${templateBucketName}/${templatePath}`);
5556
let bodyString;
57+
58+
s3 = templateBucketRegion ? new AWS.S3({ region: templateBucketRegion }) : s3;
59+
5660
try {
5761
const object = await throttlingBackOff(() =>
5862
s3

0 commit comments

Comments
 (0)