Skip to content

Commit cdecf33

Browse files
author
Tarun Belani
committed
Addressed review comments
1 parent 63ccf3f commit cdecf33

File tree

48 files changed

+6854
-368
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+6854
-368
lines changed

packages/@aws-cdk/aws-imagebuilder-alpha/README.md

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ An image pipeline provides the automation framework for building secure AMIs and
4242

4343
#### Image Pipeline Basic Usage
4444

45-
Create a simple AMI pipeline with just a recipe:
45+
Create a simple AMI pipeline with just an image recipe:
4646

4747
```ts
4848
const imageRecipe = new imagebuilder.ImageRecipe(this, 'MyImageRecipe', {
@@ -56,7 +56,7 @@ const imagePipeline = new imagebuilder.ImagePipeline(this, 'MyImagePipeline', {
5656
});
5757
```
5858

59-
Create a simple container pipeline:
59+
Create a simple container pipeline with just a container recipe:
6060

6161
```ts
6262
const containerRecipe = new imagebuilder.ContainerRecipe(this, 'MyContainerRecipe', {
@@ -98,12 +98,11 @@ const weeklyPipeline = new imagebuilder.ImagePipeline(this, 'WeeklyPipeline', {
9898
imagePipelineName: 'weekly-build-pipeline',
9999
recipe: exampleImageRecipe,
100100
schedule: {
101-
expression: events.Schedule.cron({
102-
minute: '0',
103-
hour: '6',
104-
weekDay: 'MON'
105-
}),
106-
timezone: TimeZone.AMERICA_NEW_YORK
101+
expression: events.Schedule.cron({
102+
minute: '0',
103+
hour: '6',
104+
weekDay: 'MON'
105+
})
107106
}
108107
});
109108
```
@@ -128,7 +127,6 @@ const advancedSchedulePipeline = new imagebuilder.ImagePipeline(this, 'AdvancedS
128127
recipe: exampleImageRecipe,
129128
schedule: {
130129
expression: events.Schedule.rate(Duration.days(7)),
131-
timezone: TimeZone.PST8PDT,
132130
// Only trigger when dependencies are updated (new base images, components, etc.)
133131
startCondition: imagebuilder.ScheduleStartCondition.EXPRESSION_MATCH_AND_DEPENDENCY_UPDATES_AVAILABLE,
134132
// Automatically disable after 3 consecutive failures
@@ -244,38 +242,11 @@ const controlledPipeline = new imagebuilder.ImagePipeline(this, 'ControlledPipel
244242

245243
#### Image Pipeline Events
246244

247-
##### Build State Monitoring
248-
249-
Monitor pipeline execution with EventBridge rules:
250-
251-
```ts
252-
// Monitor all pipeline events
253-
examplePipeline.onEvent('AllPipelineEvents', {
254-
target: new targets.LambdaFunction(lambdaFunction)
255-
});
256-
257-
// Monitor build state changes
258-
examplePipeline.onImageBuildStateChange('BuildStateChanges', {
259-
target: new targets.SnsTopic(topic)
260-
});
261-
262-
// Monitor build failures for alerts
263-
examplePipeline.onImageBuildFailed('BuildFailureAlert', {
264-
target: new targets.SqsQueue(queue)
265-
});
266-
```
267-
268245
##### Pipeline Event Handling
269246

270247
Handle specific pipeline events:
271248

272249
```ts
273-
// React to successful builds
274-
examplePipeline.onImageBuildSuccess('BuildSuccessHandler', {
275-
target: new targets.LambdaFunction(lambdaFunction),
276-
description: 'Trigger deployment after successful build'
277-
});
278-
279250
// Monitor CVE detection
280251
examplePipeline.onCVEDetected('CVEAlert', {
281252
target: new targets.SnsTopic(topic)
@@ -289,7 +260,7 @@ examplePipeline.onImagePipelineAutoDisabled('PipelineDisabledAlert', {
289260

290261
#### Importing Image Pipelines
291262

292-
Reference existing pipelines created outside of CDK:
263+
Reference existing pipelines created outside CDK:
293264

294265
```ts
295266
// Import by name

packages/@aws-cdk/aws-imagebuilder-alpha/lib/image-pipeline.ts

Lines changed: 30 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { IInfrastructureConfiguration, InfrastructureConfiguration } from './inf
1111
import {
1212
buildImageScanningConfiguration,
1313
buildImageTestsConfiguration,
14+
buildWorkflows,
1415
} from './private/image-and-pipeline-props-helper';
1516
import { defaultExecutionRolePolicy, getExecutionRole } from './private/policy-helper';
1617
import { IRecipeBase } from './recipe-base';
@@ -19,7 +20,7 @@ import { WorkflowConfiguration } from './workflow';
1920
const IMAGE_PIPELINE_SYMBOL = Symbol.for('@aws-cdk/aws-imagebuilder-alpha.ImagePipeline');
2021

2122
/**
22-
* An EC2 Image Builder Image Pipline.
23+
* An EC2 Image Builder Image Pipeline.
2324
*/
2425
export interface IImagePipeline extends cdk.IResource {
2526
/**
@@ -85,46 +86,6 @@ export interface IImagePipeline extends cdk.IResource {
8586
*/
8687
onCVEDetected(id: string, options?: events.OnEventOptions): events.Rule;
8788

88-
/**
89-
* Creates an EventBridge rule for Image Builder image state change events.
90-
*
91-
* @param id Unique identifier for the rule
92-
* @param options Configuration options for the event rule
93-
*
94-
* @see https://docs.aws.amazon.com/imagebuilder/latest/userguide/integ-eventbridge.html
95-
*/
96-
onImageBuildStateChange(id: string, options?: events.OnEventOptions): events.Rule;
97-
98-
/**
99-
* Creates an EventBridge rule for Image Builder image completion events.
100-
*
101-
* @param id Unique identifier for the rule
102-
* @param options Configuration options for the event rule
103-
*
104-
* @see https://docs.aws.amazon.com/imagebuilder/latest/userguide/integ-eventbridge.html
105-
*/
106-
onImageBuildCompleted(id: string, options?: events.OnEventOptions): events.Rule;
107-
108-
/**
109-
* Creates an EventBridge rule for Image Builder image failure events.
110-
*
111-
* @param id Unique identifier for the rule
112-
* @param options Configuration options for the event rule
113-
*
114-
* @see https://docs.aws.amazon.com/imagebuilder/latest/userguide/integ-eventbridge.html
115-
*/
116-
onImageBuildFailed(id: string, options?: events.OnEventOptions): events.Rule;
117-
118-
/**
119-
* Creates an EventBridge rule for Image Builder image success events.
120-
*
121-
* @param id Unique identifier for the rule
122-
* @param options Configuration options for the event rule
123-
*
124-
* @see https://docs.aws.amazon.com/imagebuilder/latest/userguide/integ-eventbridge.html
125-
*/
126-
onImageBuildSuccess(id: string, options?: events.OnEventOptions): events.Rule;
127-
12889
/**
12990
* Creates an EventBridge rule for Image Builder image pipeline automatically disabled events.
13091
*
@@ -134,16 +95,6 @@ export interface IImagePipeline extends cdk.IResource {
13495
* @see https://docs.aws.amazon.com/imagebuilder/latest/userguide/integ-eventbridge.html
13596
*/
13697
onImagePipelineAutoDisabled(id: string, options?: events.OnEventOptions): events.Rule;
137-
138-
/**
139-
* Creates an EventBridge rule for Image Builder wait for action events
140-
*
141-
* @param id Unique identifier for the rule
142-
* @param options Configuration options for the event rule
143-
*
144-
* @see https://docs.aws.amazon.com/imagebuilder/latest/userguide/integ-eventbridge.html
145-
*/
146-
onWaitForAction(id: string, options?: events.OnEventOptions): events.Rule;
14798
}
14899

149100
/**
@@ -232,7 +183,7 @@ export interface ImagePipelineProps {
232183

233184
/**
234185
* The log group to use for images created from the image pipeline. By default, a log group will be created with the
235-
* format `/aws/imagebuilder/<image-name>`, with a 90-day retention policy.
186+
* format `/aws/imagebuilder/<image-name>`.
236187
*
237188
* @default - a log group will be created
238189
*/
@@ -295,9 +246,11 @@ export interface ImagePipelineSchedule {
295246
readonly expression: events.Schedule;
296247

297248
/**
298-
* The number of consecutive failures allowed before the pipeline is automatically disabled.
249+
* The number of consecutive failures allowed before the pipeline is automatically disabled. This value must be
250+
* between 1 and 10.
299251
*
300-
* @default - the pipeline will not be disabled automatically on consecutive failures
252+
* @default - no auto-disable policy is configured and the pipeline is not automatically disabled on consecutive
253+
* failures
301254
*/
302255
readonly autoDisableFailureCount?: number;
303256

@@ -307,13 +260,6 @@ export interface ImagePipelineSchedule {
307260
* @default ScheduleStartCondition.EXPRESSION_MATCH_AND_DEPENDENCY_UPDATES_AVAILABLE
308261
*/
309262
readonly startCondition?: ScheduleStartCondition;
310-
311-
/**
312-
* The timezone in which the schedule expression is evaluated.
313-
*
314-
* @default UTC
315-
*/
316-
readonly timezone?: cdk.TimeZone;
317263
}
318264

319265
/**
@@ -405,7 +351,15 @@ abstract class ImagePipelineBase extends cdk.Resource implements IImagePipeline
405351
* @see https://docs.aws.amazon.com/imagebuilder/latest/userguide/integ-eventbridge.html
406352
*/
407353
public onEvent(id: string, options: events.OnEventOptions = {}): events.Rule {
408-
return this.buildEvent(id, options);
354+
const rule = new events.Rule(this, id, options);
355+
rule.addTarget(options.target);
356+
rule.addEventPattern({
357+
source: ['aws.imagebuilder'],
358+
resources: [this.imagePipelineArn],
359+
...(options.eventPattern?.detailType?.length && { detailType: options.eventPattern.detailType }),
360+
...(options.eventPattern?.detail !== undefined && { detail: options.eventPattern.detail }),
361+
});
362+
return rule;
409363
}
410364

411365
/**
@@ -417,57 +371,7 @@ abstract class ImagePipelineBase extends cdk.Resource implements IImagePipeline
417371
* @see https://docs.aws.amazon.com/imagebuilder/latest/userguide/integ-eventbridge.html
418372
*/
419373
public onCVEDetected(id: string, options: events.OnEventOptions = {}): events.Rule {
420-
return this.buildEvent(id, options, 'EC2 Image Builder CVE Detected');
421-
}
422-
423-
/**
424-
* Creates an EventBridge rule for Image Builder image state change events.
425-
*
426-
* @param id Unique identifier for the rule
427-
* @param options Configuration options for the event rule
428-
*
429-
* @see https://docs.aws.amazon.com/imagebuilder/latest/userguide/integ-eventbridge.html
430-
*/
431-
public onImageBuildStateChange(id: string, options: events.OnEventOptions = {}): events.Rule {
432-
return this.buildEvent(id, options, 'EC2 Image Builder Image State Change');
433-
}
434-
435-
/**
436-
* Creates an EventBridge rule for Image Builder image completion events.
437-
*
438-
* @param id Unique identifier for the rule
439-
* @param options Configuration options for the event rule
440-
*
441-
* @see https://docs.aws.amazon.com/imagebuilder/latest/userguide/integ-eventbridge.html
442-
*/
443-
public onImageBuildCompleted(id: string, options: events.OnEventOptions = {}): events.Rule {
444-
return this.buildEvent(id, options, 'EC2 Image Builder Image State Change', {
445-
state: { status: ['AVAILABLE', 'CANCELLED', 'FAILED'] },
446-
});
447-
}
448-
449-
/**
450-
* Creates an EventBridge rule for Image Builder image failure events.
451-
*
452-
* @param id Unique identifier for the rule
453-
* @param options Configuration options for the event rule
454-
*
455-
* @see https://docs.aws.amazon.com/imagebuilder/latest/userguide/integ-eventbridge.html
456-
*/
457-
public onImageBuildFailed(id: string, options: events.OnEventOptions = {}): events.Rule {
458-
return this.buildEvent(id, options, 'EC2 Image Builder Image State Change', { state: { status: ['FAILED'] } });
459-
}
460-
461-
/**
462-
* Creates an EventBridge rule for Image Builder image success events.
463-
*
464-
* @param id Unique identifier for the rule
465-
* @param options Configuration options for the event rule
466-
*
467-
* @see https://docs.aws.amazon.com/imagebuilder/latest/userguide/integ-eventbridge.html
468-
*/
469-
public onImageBuildSuccess(id: string, options?: events.OnEventOptions): events.Rule {
470-
return this.buildEvent(id, options, 'EC2 Image Builder Image State Change', { state: { status: ['AVAILABLE'] } });
374+
return this.onEvent(id, { ...options, eventPattern: { detailType: ['EC2 Image Builder CVE Detected'] } });
471375
}
472376

473377
/**
@@ -479,36 +383,10 @@ abstract class ImagePipelineBase extends cdk.Resource implements IImagePipeline
479383
* @see https://docs.aws.amazon.com/imagebuilder/latest/userguide/integ-eventbridge.html
480384
*/
481385
public onImagePipelineAutoDisabled(id: string, options: events.OnEventOptions = {}): events.Rule {
482-
return this.buildEvent(id, options, 'EC2 Image Builder Image Pipeline Automatically Disabled');
483-
}
484-
485-
/**
486-
* Creates an EventBridge rule for Image Builder wait for action events
487-
*
488-
* @param id Unique identifier for the rule
489-
* @param options Configuration options for the event rule
490-
*
491-
* @see https://docs.aws.amazon.com/imagebuilder/latest/userguide/integ-eventbridge.html
492-
*/
493-
public onWaitForAction(id: string, options: events.OnEventOptions = {}): events.Rule {
494-
return this.buildEvent(id, options, 'EC2 Image Builder Workflow Step Waiting');
495-
}
496-
497-
protected buildEvent(
498-
id: string,
499-
options: events.OnEventOptions = {},
500-
detailType?: string,
501-
detail?: { [key: string]: any },
502-
): events.Rule {
503-
const rule = new events.Rule(this, id, options);
504-
rule.addTarget(options.target);
505-
rule.addEventPattern({
506-
source: ['aws.imagebuilder'],
507-
resources: [this.imagePipelineArn],
508-
...(detailType && { detailType: [detailType] }),
509-
...(detail !== undefined && { detail }),
386+
return this.onEvent(id, {
387+
...options,
388+
eventPattern: { detailType: ['EC2 Image Builder Image Pipeline Automatically Disabled'] },
510389
});
511-
return rule;
512390
}
513391
}
514392

@@ -618,14 +496,16 @@ export class ImagePipeline extends ImagePipelineBase {
618496
description: props.description,
619497
...(props.recipe._isImageRecipe() && { imageRecipeArn: props.recipe.imageRecipeArn }),
620498
...(props.recipe._isContainerRecipe() && { containerRecipeArn: props.recipe.containerRecipeArn }),
499+
...(props.enabled !== undefined && { status: props.enabled ? 'ENABLED' : 'DISABLED' }),
621500
infrastructureConfigurationArn: this.infrastructureConfiguration.infrastructureConfigurationArn,
622501
distributionConfigurationArn: props.distributionConfiguration?.distributionConfigurationArn,
502+
enhancedImageMetadataEnabled: props.enhancedImageMetadataEnabled,
503+
executionRole: this.executionRole?.roleArn,
623504
schedule: this.buildSchedule(props),
624505
loggingConfiguration: this.buildLoggingConfiguration(props),
625-
enhancedImageMetadataEnabled: props.enhancedImageMetadataEnabled,
626506
imageTestsConfiguration: buildImageTestsConfiguration(props),
627507
imageScanningConfiguration: buildImageScanningConfiguration(scope, props),
628-
executionRole: this.executionRole?.roleArn,
508+
workflows: buildWorkflows(props),
629509
tags: props.tags,
630510
});
631511

@@ -673,7 +553,6 @@ export class ImagePipeline extends ImagePipelineBase {
673553

674554
return {
675555
scheduleExpression: schedule.expression.expressionString,
676-
...(schedule.timezone && { timezone: schedule.timezone.timezoneName }),
677556
...(schedule.autoDisableFailureCount !== undefined && {
678557
autoDisablePolicy: {
679558
failureCount: schedule.autoDisableFailureCount,
@@ -685,6 +564,12 @@ export class ImagePipeline extends ImagePipelineBase {
685564
};
686565
}
687566

567+
/**
568+
* Generates the loggingConfiguration property into the `LoggingConfiguration` type in the CloudFormation L1
569+
* definition.
570+
*
571+
* @param props Props input for the construct
572+
*/
688573
private buildLoggingConfiguration = (
689574
props: ImagePipelineProps,
690575
): CfnImagePipeline.PipelineLoggingConfigurationProperty | undefined => {

0 commit comments

Comments
 (0)