Commit c36f43d
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
File tree
22 files changed
+3747
-0
lines changed- packages/@aws-cdk/aws-imagebuilder-alpha
- lib
- test
- integ.all-parameters.distribution-configuration.js.snapshot
- integ.default-parameters.distribution-configuration.js.snapshot
22 files changed
+3747
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
296 | 296 | | |
297 | 297 | | |
298 | 298 | | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
0 commit comments