Skip to content

Commit 142d0d2

Browse files
committed
Adds properties to ImagePipeline construct
* allow adding a schedule to the image pipeline * subscribe to the pipeline SNS from outside the component
1 parent 925f342 commit 142d0d2

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/index.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ export interface ImagePipelineProps {
129129

130130
export class ImagePipeline extends Construct {
131131
imageRecipeComponents: imagebuilder.CfnImageRecipe.ComponentConfigurationProperty[];
132+
readonly pipeline: imagebuilder.CfnImagePipeline;
133+
readonly builderSnsTopic: sns.Topic;
132134

133135
constructor(scope: Construct, id: string, props: ImagePipelineProps) {
134136
super(scope, id);
@@ -140,13 +142,13 @@ export class ImagePipeline extends Construct {
140142
const profileName = `${uid}Profile`;
141143

142144
// Construct code below
143-
const topic = new sns.Topic(this, 'ImageBuilderTopic', {
145+
this.builderSnsTopic = new sns.Topic(this, 'ImageBuilderTopic', {
144146
displayName: 'Image Builder Notify',
145147
masterKey: props.kmsKey,
146148
});
147149

148150
if (props.email != null) {
149-
topic.addSubscription(new subscriptions.EmailSubscription(props.email));
151+
this.builderSnsTopic.addSubscription(new subscriptions.EmailSubscription(props.email));
150152
}
151153

152154
const role = new iam.Role(this, 'Role', {
@@ -174,15 +176,15 @@ export class ImagePipeline extends Construct {
174176
name: `${uid}InfraConfig`,
175177
description: 'Example Infrastructure Configuration for Image Builder',
176178
instanceTypes: props.instanceTypes ?? ['t3.medium', 'm5.large', 'm5.xlarge'],
177-
snsTopicArn: topic.topicArn,
179+
snsTopicArn: this.builderSnsTopic.topicArn,
178180
});
179181
} else {
180182
infrastructureConfig = new imagebuilder.CfnInfrastructureConfiguration(this, 'InfrastructureConfiguration', {
181183
instanceProfileName: profileName,
182184
name: `${uid}InfraConfig`,
183185
description: 'Example Infrastructure Configuration for Image Builder',
184186
instanceTypes: props.instanceTypes ?? ['t3.medium', 'm5.large', 'm5.xlarge'],
185-
snsTopicArn: topic.topicArn,
187+
snsTopicArn: this.builderSnsTopic.topicArn,
186188
securityGroupIds: props.securityGroups,
187189
subnetId: props.subnetId,
188190
});
@@ -325,9 +327,9 @@ export class ImagePipeline extends Construct {
325327
},
326328
memorySize: 256,
327329
});
328-
amiSsmUpdateLambda.addEventSource(new SnsEventSource(topic, {}));
330+
amiSsmUpdateLambda.addEventSource(new SnsEventSource(this.builderSnsTopic, {}));
329331
}
330-
new imagebuilder.CfnImagePipeline(this, 'ImagePipeline', imagePipelineProps);
332+
this.pipeline = new imagebuilder.CfnImagePipeline(this, 'ImagePipeline', imagePipelineProps);
331333
}
332334

333335
/**

test/imagepipeline.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,17 @@ test('Image Pipeline has Inspector vulnerability scans configured', () => {
237237
},
238238
});
239239
});
240+
241+
242+
test('ImagePipeline exposes components as properties', () => {
243+
const app = new cdk.App();
244+
const testStack = new cdk.Stack(app, 'testStack', {
245+
env: {
246+
account: process.env.CDK_DEFAULT_ACCOUNT,
247+
region: process.env.CDK_DEFAULT_REGION,
248+
},
249+
});
250+
const sut = new ImagePipeline(testStack, 'ImagePipelineStack', props);
251+
expect(sut.pipeline).toBeDefined();
252+
expect(sut.builderSnsTopic).toBeDefined();
253+
});

0 commit comments

Comments
 (0)