Skip to content

Commit c36f43d

Browse files
authored
feat(imagebuilder-alpha): add support for Distribution Configuration Construct (#36005)
### Issue # aws/aws-cdk-rfcs#789 ### Reason for this change This change adds a new alpha module for EC2 Image Builder L2 Constructs (`@aws-cdk/aws-imagebuilder-alpha`), as outlined in aws/aws-cdk-rfcs#789. This PR specifically implements the `DistributionConfiguration` construct. ### Description of changes This change implements the `DistributionConfiguration` construct, which is a higher-level construct of [`CfnDistributionConfiguration`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_imagebuilder.CfnDistributionConfiguration.html). #### Example ```ts const distributionConfiguration = new imagebuilder.DistributionConfiguration(this, 'DistributionConfiguration', { distributionConfigurationName: 'test-distribution-configuration', description: 'A Distribution Configuration', amiDistributions: [ { // Distribute AMI to us-east-2 and publish the AMI ID to an SSM parameter region: 'us-east-2', ssmParameters: [ { parameter: ssm.StringParameter.fromStringParameterAttributes(this, 'CrossRegionParameter', { parameterName: '/imagebuilder/ami', forceDynamicReference: true }) } ] } ] }); // For AMI-based image builds - add an AMI distribution in the current region distributionConfiguration.addAmiDistributions({ amiName: 'imagebuilder-{{ imagebuilder:buildDate }}', amiDescription: 'Build AMI', amiKmsKey: kms.Key.fromLookup(this, 'ComponentKey', { aliasName: 'alias/distribution-encryption-key' }), // Copy the AMI to different accounts amiTargetAccountIds: ['123456789012', '098765432109'], // Add launch permissions on the AMI amiLaunchPermission: { organizationArns: [ this.formatArn({ region: '', service: 'organizations', resource: 'organization', resourceName: 'o-1234567abc' }) ], organizationalUnitArns: [ this.formatArn({ region: '', service: 'organizations', resource: 'ou', resourceName: 'o-1234567abc/ou-a123-b4567890' }) ], userGroups: ['all'], userIds: ['234567890123'] }, // Attach tags to the AMI amiTags: { Environment: 'production', Version: '{{ imagebuilder:buildVersion }}' }, // Optional - publish the distributed AMI ID to an SSM parameter ssmParameters: [ { parameter: ssm.StringParameter.fromStringParameterAttributes(this, 'Parameter', { parameterName: '/imagebuilder/ami', forceDynamicReference: true }) }, { amiAccount: '098765432109', dataType: ssm.ParameterDataType.TEXT, parameter: ssm.StringParameter.fromStringParameterAttributes(this, 'CrossAccountParameter', { parameterName: 'imagebuilder-prod-ami', forceDynamicReference: true }) } ], // Optional - create a new launch template version with the distributed AMI ID launchTemplates: [ { launchTemplate: ec2.LaunchTemplate.fromLaunchTemplateAttributes(this, 'LaunchTemplate', { launchTemplateName: 'imagebuilder-ami' }), setDefaultVersion: true }, { accountId: '098765432109', launchTemplate: ec2.LaunchTemplate.fromLaunchTemplateAttributes(this, 'CrossAccountLaunchTemplate', { launchTemplateName: 'imagebuilder-cross-account-ami' }), setDefaultVersion: true } ], // Optional - enable Fast Launch on an imported launch template fastLaunchConfigurations: [ { enabled: true, launchTemplate: ec2.LaunchTemplate.fromLaunchTemplateAttributes(this, 'FastLaunchLT', { launchTemplateName: 'fast-launch-lt' }), maxParallelLaunches: 10, targetSnapshotCount: 2 } ], // Optional - license configurations to apply to the AMI licenseConfigurationArns: [ 'arn:aws:license-manager:us-west-2:123456789012:license-configuration:lic-abcdefghijklmnopqrstuvwxyz' ] }); ``` ### Describe any new or updated permissions being added N/A - new L2 construct in alpha module ### Description of how you validated changes Validated with unit tests and integration tests. Manually verified generated CFN templates as well. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 0851ffd commit c36f43d

22 files changed

+3747
-0
lines changed

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

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,110 @@ const infrastructureConfiguration = new imagebuilder.InfrastructureConfiguration
296296
}
297297
});
298298
```
299+
300+
### Distribution Configuration
301+
302+
Distribution configuration defines how and where your built images are distributed after successful creation. For AMIs,
303+
this includes target AWS Regions, KMS encryption keys, account sharing permissions, License Manager associations, and
304+
launch template configurations. For container images, it specifies the target Amazon ECR repositories across regions.
305+
A distribution configuration can be associated with an image or an image pipeline to define these distribution settings
306+
for image builds.
307+
308+
```ts
309+
const distributionConfiguration = new imagebuilder.DistributionConfiguration(this, 'DistributionConfiguration', {
310+
distributionConfigurationName: 'test-distribution-configuration',
311+
description: 'A Distribution Configuration',
312+
amiDistributions: [
313+
{
314+
// Distribute AMI to us-east-2 and publish the AMI ID to an SSM parameter
315+
region: 'us-east-2',
316+
ssmParameters: [
317+
{
318+
parameter: ssm.StringParameter.fromStringParameterAttributes(this, 'CrossRegionParameter', {
319+
parameterName: '/imagebuilder/ami',
320+
forceDynamicReference: true
321+
})
322+
}
323+
]
324+
}
325+
]
326+
});
327+
328+
// For AMI-based image builds - add an AMI distribution in the current region
329+
distributionConfiguration.addAmiDistributions({
330+
amiName: 'imagebuilder-{{ imagebuilder:buildDate }}',
331+
amiDescription: 'Build AMI',
332+
amiKmsKey: kms.Key.fromLookup(this, 'ComponentKey', { aliasName: 'alias/distribution-encryption-key' }),
333+
// Copy the AMI to different accounts
334+
amiTargetAccountIds: ['123456789012', '098765432109'],
335+
// Add launch permissions on the AMI
336+
amiLaunchPermission: {
337+
organizationArns: [
338+
this.formatArn({ region: '', service: 'organizations', resource: 'organization', resourceName: 'o-1234567abc' })
339+
],
340+
organizationalUnitArns: [
341+
this.formatArn({
342+
region: '',
343+
service: 'organizations',
344+
resource: 'ou',
345+
resourceName: 'o-1234567abc/ou-a123-b4567890'
346+
})
347+
],
348+
isPublicUserGroup: true,
349+
accountIds: ['234567890123']
350+
},
351+
// Attach tags to the AMI
352+
amiTags: {
353+
Environment: 'production',
354+
Version: '{{ imagebuilder:buildVersion }}'
355+
},
356+
// Optional - publish the distributed AMI ID to an SSM parameter
357+
ssmParameters: [
358+
{
359+
parameter: ssm.StringParameter.fromStringParameterAttributes(this, 'Parameter', {
360+
parameterName: '/imagebuilder/ami',
361+
forceDynamicReference: true
362+
})
363+
},
364+
{
365+
amiAccount: '098765432109',
366+
dataType: ssm.ParameterDataType.TEXT,
367+
parameter: ssm.StringParameter.fromStringParameterAttributes(this, 'CrossAccountParameter', {
368+
parameterName: 'imagebuilder-prod-ami',
369+
forceDynamicReference: true
370+
})
371+
}
372+
],
373+
// Optional - create a new launch template version with the distributed AMI ID
374+
launchTemplates: [
375+
{
376+
launchTemplate: ec2.LaunchTemplate.fromLaunchTemplateAttributes(this, 'LaunchTemplate', {
377+
launchTemplateId: 'lt-1234'
378+
}),
379+
setDefaultVersion: true
380+
},
381+
{
382+
accountId: '123456789012',
383+
launchTemplate: ec2.LaunchTemplate.fromLaunchTemplateAttributes(this, 'CrossAccountLaunchTemplate', {
384+
launchTemplateId: 'lt-5678'
385+
}),
386+
setDefaultVersion: true
387+
}
388+
],
389+
// Optional - enable Fast Launch on an imported launch template
390+
fastLaunchConfigurations: [
391+
{
392+
enabled: true,
393+
launchTemplate: ec2.LaunchTemplate.fromLaunchTemplateAttributes(this, 'FastLaunchLT', {
394+
launchTemplateName: 'fast-launch-lt'
395+
}),
396+
maxParallelLaunches: 10,
397+
targetSnapshotCount: 2
398+
}
399+
],
400+
// Optional - license configurations to apply to the AMI
401+
licenseConfigurationArns: [
402+
'arn:aws:license-manager:us-west-2:123456789012:license-configuration:lic-abcdefghijklmnopqrstuvwxyz'
403+
]
404+
});
405+
```

0 commit comments

Comments
 (0)