Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for cross region s3 template processing #1221

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading