Skip to content

Commit 6051039

Browse files
authored
feat(imagebuilder-alpha): add support for Distribution Configuration Construct (#36108)
### Reason for this change Reapplying #36005, following revert in 36103. Adds JSDoc examples in `Repository` where it was causing issues. ### Describe any new or updated permissions being added N/A ### Description of how you validated changes Built locally, tests are passing ### 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 1413892 commit 6051039

23 files changed

+3784
-0
lines changed

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

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,146 @@ const infrastructureConfiguration = new imagebuilder.InfrastructureConfiguration
9292
}
9393
});
9494
```
95+
96+
### Distribution Configuration
97+
98+
Distribution configuration defines how and where your built images are distributed after successful creation. For AMIs,
99+
this includes target AWS Regions, KMS encryption keys, account sharing permissions, License Manager associations, and
100+
launch template configurations. For container images, it specifies the target Amazon ECR repositories across regions.
101+
A distribution configuration can be associated with an image or an image pipeline to define these distribution settings
102+
for image builds.
103+
104+
#### AMI Distributions
105+
106+
AMI distributions can be defined to copy and modify AMIs in different accounts and regions, and apply them to launch
107+
templates, SSM parameters, etc.:
108+
109+
```ts
110+
const distributionConfiguration = new imagebuilder.DistributionConfiguration(this, 'DistributionConfiguration', {
111+
distributionConfigurationName: 'test-distribution-configuration',
112+
description: 'A Distribution Configuration',
113+
amiDistributions: [
114+
{
115+
// Distribute AMI to us-east-2 and publish the AMI ID to an SSM parameter
116+
region: 'us-east-2',
117+
ssmParameters: [
118+
{
119+
parameter: ssm.StringParameter.fromStringParameterAttributes(this, 'CrossRegionParameter', {
120+
parameterName: '/imagebuilder/ami',
121+
forceDynamicReference: true
122+
})
123+
}
124+
]
125+
}
126+
]
127+
});
128+
129+
// For AMI-based image builds - add an AMI distribution in the current region
130+
distributionConfiguration.addAmiDistributions({
131+
amiName: 'imagebuilder-{{ imagebuilder:buildDate }}',
132+
amiDescription: 'Build AMI',
133+
amiKmsKey: kms.Key.fromLookup(this, 'ComponentKey', { aliasName: 'alias/distribution-encryption-key' }),
134+
// Copy the AMI to different accounts
135+
amiTargetAccountIds: ['123456789012', '098765432109'],
136+
// Add launch permissions on the AMI
137+
amiLaunchPermission: {
138+
organizationArns: [
139+
this.formatArn({ region: '', service: 'organizations', resource: 'organization', resourceName: 'o-1234567abc' })
140+
],
141+
organizationalUnitArns: [
142+
this.formatArn({
143+
region: '',
144+
service: 'organizations',
145+
resource: 'ou',
146+
resourceName: 'o-1234567abc/ou-a123-b4567890'
147+
})
148+
],
149+
isPublicUserGroup: true,
150+
accountIds: ['234567890123']
151+
},
152+
// Attach tags to the AMI
153+
amiTags: {
154+
Environment: 'production',
155+
Version: '{{ imagebuilder:buildVersion }}'
156+
},
157+
// Optional - publish the distributed AMI ID to an SSM parameter
158+
ssmParameters: [
159+
{
160+
parameter: ssm.StringParameter.fromStringParameterAttributes(this, 'Parameter', {
161+
parameterName: '/imagebuilder/ami',
162+
forceDynamicReference: true
163+
})
164+
},
165+
{
166+
amiAccount: '098765432109',
167+
dataType: ssm.ParameterDataType.TEXT,
168+
parameter: ssm.StringParameter.fromStringParameterAttributes(this, 'CrossAccountParameter', {
169+
parameterName: 'imagebuilder-prod-ami',
170+
forceDynamicReference: true
171+
})
172+
}
173+
],
174+
// Optional - create a new launch template version with the distributed AMI ID
175+
launchTemplates: [
176+
{
177+
launchTemplate: ec2.LaunchTemplate.fromLaunchTemplateAttributes(this, 'LaunchTemplate', {
178+
launchTemplateId: 'lt-1234'
179+
}),
180+
setDefaultVersion: true
181+
},
182+
{
183+
accountId: '123456789012',
184+
launchTemplate: ec2.LaunchTemplate.fromLaunchTemplateAttributes(this, 'CrossAccountLaunchTemplate', {
185+
launchTemplateId: 'lt-5678'
186+
}),
187+
setDefaultVersion: true
188+
}
189+
],
190+
// Optional - enable Fast Launch on an imported launch template
191+
fastLaunchConfigurations: [
192+
{
193+
enabled: true,
194+
launchTemplate: ec2.LaunchTemplate.fromLaunchTemplateAttributes(this, 'FastLaunchLT', {
195+
launchTemplateName: 'fast-launch-lt'
196+
}),
197+
maxParallelLaunches: 10,
198+
targetSnapshotCount: 2
199+
}
200+
],
201+
// Optional - license configurations to apply to the AMI
202+
licenseConfigurationArns: [
203+
'arn:aws:license-manager:us-west-2:123456789012:license-configuration:lic-abcdefghijklmnopqrstuvwxyz'
204+
]
205+
});
206+
```
207+
208+
#### Container Distributions
209+
210+
##### Container repositories
211+
212+
Container distributions can be configured to distribute to ECR repositories:
213+
214+
```ts
215+
const ecrRepository = ecr.Repository.fromRepositoryName(this, 'ECRRepository', 'my-repo');
216+
const imageBuilderRepository = imagebuilder.Repository.fromEcr(ecrRepository);
217+
```
218+
219+
##### Defining a container distribution
220+
221+
You can configure the container repositories as well as the description and tags applied to the distributed container
222+
images:
223+
224+
```ts
225+
const ecrRepository = ecr.Repository.fromRepositoryName(this, 'ECRRepository', 'my-repo');
226+
const containerRepository = imagebuilder.Repository.fromEcr(ecrRepository);
227+
const containerDistributionConfiguration = new imagebuilder.DistributionConfiguration(
228+
this,
229+
'ContainerDistributionConfiguration'
230+
);
231+
232+
containerDistributionConfiguration.addContainerDistributions({
233+
containerRepository,
234+
containerDescription: 'Test container image',
235+
containerTags: ['latest', 'latest-1.0']
236+
});
237+
```

0 commit comments

Comments
 (0)