Skip to content

Commit 5d3ff75

Browse files
author
Tarun Belani
committed
feat(imagebuilder): add support for EC2 Image Builder L2 Constructs - Distribution Configuration
1 parent 0d773b1 commit 5d3ff75

22 files changed

+3309
-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
@@ -92,3 +92,110 @@ 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+
```ts
105+
const distributionConfiguration = new imagebuilder.DistributionConfiguration(this, 'DistributionConfiguration', {
106+
distributionConfigurationName: 'test-distribution-configuration',
107+
description: 'A Distribution Configuration',
108+
amiDistributions: [
109+
{
110+
// Distribute AMI to us-east-2 and publish the AMI ID to an SSM parameter
111+
region: 'us-east-2',
112+
ssmParameters: [
113+
{
114+
parameter: ssm.StringParameter.fromStringParameterAttributes(this, 'CrossRegionParameter', {
115+
parameterName: '/imagebuilder/ami',
116+
forceDynamicReference: true
117+
})
118+
}
119+
]
120+
}
121+
]
122+
});
123+
124+
// For AMI-based image builds - add an AMI distribution in the current region
125+
distributionConfiguration.addAmiDistributions({
126+
amiName: 'imagebuilder-{{ imagebuilder:buildDate }}',
127+
amiDescription: 'Build AMI',
128+
amiKmsKey: kms.Key.fromLookup(this, 'ComponentKey', { aliasName: 'alias/distribution-encryption-key' }),
129+
// Copy the AMI to different accounts
130+
amiTargetAccountIds: ['123456789012', '098765432109'],
131+
// Add launch permissions on the AMI
132+
amiLaunchPermission: {
133+
organizationArns: [
134+
this.formatArn({ region: '', service: 'organizations', resource: 'organization', resourceName: 'o-1234567abc' })
135+
],
136+
organizationalUnitArns: [
137+
this.formatArn({
138+
region: '',
139+
service: 'organizations',
140+
resource: 'ou',
141+
resourceName: 'o-1234567abc/ou-a123-b4567890'
142+
})
143+
],
144+
isPublicUserGroup: true,
145+
accountIds: ['234567890123']
146+
},
147+
// Attach tags to the AMI
148+
amiTags: {
149+
Environment: 'production',
150+
Version: '{{ imagebuilder:buildVersion }}'
151+
},
152+
// Optional - publish the distributed AMI ID to an SSM parameter
153+
ssmParameters: [
154+
{
155+
parameter: ssm.StringParameter.fromStringParameterAttributes(this, 'Parameter', {
156+
parameterName: '/imagebuilder/ami',
157+
forceDynamicReference: true
158+
})
159+
},
160+
{
161+
amiAccount: '098765432109',
162+
dataType: ssm.ParameterDataType.TEXT,
163+
parameter: ssm.StringParameter.fromStringParameterAttributes(this, 'CrossAccountParameter', {
164+
parameterName: 'imagebuilder-prod-ami',
165+
forceDynamicReference: true
166+
})
167+
}
168+
],
169+
// Optional - create a new launch template version with the distributed AMI ID
170+
launchTemplates: [
171+
{
172+
launchTemplate: ec2.LaunchTemplate.fromLaunchTemplateAttributes(this, 'LaunchTemplate', {
173+
launchTemplateName: 'imagebuilder-ami'
174+
}),
175+
setDefaultVersion: true
176+
},
177+
{
178+
accountId: '123456789012',
179+
launchTemplate: ec2.LaunchTemplate.fromLaunchTemplateAttributes(this, 'CrossAccountLaunchTemplate', {
180+
launchTemplateName: 'imagebuilder-cross-account-ami'
181+
}),
182+
setDefaultVersion: true
183+
}
184+
],
185+
// Optional - enable Fast Launch on an imported launch template
186+
fastLaunchConfigurations: [
187+
{
188+
enabled: true,
189+
launchTemplate: ec2.LaunchTemplate.fromLaunchTemplateAttributes(this, 'FastLaunchLT', {
190+
launchTemplateName: 'fast-launch-lt'
191+
}),
192+
maxParallelLaunches: 10,
193+
targetSnapshotCount: 2
194+
}
195+
],
196+
// Optional - license configurations to apply to the AMI
197+
licenseConfigurationArns: [
198+
'arn:aws:license-manager:us-west-2:123456789012:license-configuration:lic-abcdefghijklmnopqrstuvwxyz'
199+
]
200+
});
201+
```

0 commit comments

Comments
 (0)