Skip to content

Conversation

@tarunb12
Copy link
Contributor

Issue

aws/aws-cdk-rfcs#789

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 LifecyclePolicy construct.

Description of changes

This change implements the ImageRecipe construct, which is a higher-level construct of CfnLifecyclePolicy.

Example

const graduatedPolicy = new imagebuilder.LifecyclePolicy(this, 'GraduatedPolicy', {
  resourceType: imagebuilder.LifecyclePolicyResourceType.AMI_IMAGE,
  details: [
    {
      // First: Deprecate images after 30 days
      action: { 
        type: imagebuilder.LifecyclePolicyActionType.DEPRECATE,
        includeAmis: true
      },
      filter: { 
        age: Duration.days(30),
        retainAtLeast: 5
      }
    },
    {
      // Second: Disable images after 60 days  
      action: { 
        type: imagebuilder.LifecyclePolicyActionType.DISABLE,
        includeAmis: true
      },
      filter: { 
        age: Duration.days(60),
        retainAtLeast: 3
      }
    },
    {
      // Finally: Delete images after 90 days
      action: { 
        type: imagebuilder.LifecyclePolicyActionType.DELETE,
        includeAmis: true,
        includeSnapshots: true
      },
      filter: { 
        age: Duration.days(90),
        retainAtLeast: 1
      }
    }
  ],
  resourceSelection: {
    tags: { Environment: 'production' }
  }
});

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


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added p2 valued-contributor [Pilot] contributed between 6-12 PRs to the CDK labels Nov 22, 2025
@aws-cdk-automation aws-cdk-automation requested a review from a team November 22, 2025 08:41
@aws-cdk-automation aws-cdk-automation added the pr/needs-further-review PR requires additional review from our team specialists due to the scope or complexity of changes. label Nov 22, 2025
@tarunb12 tarunb12 force-pushed the imagebuilder-lifecycle-policy branch from 438362d to 4099439 Compare November 22, 2025 09:14
@tarunb12 tarunb12 marked this pull request as ready for review November 22, 2025 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p2 pr/needs-further-review PR requires additional review from our team specialists due to the scope or complexity of changes. valued-contributor [Pilot] contributed between 6-12 PRs to the CDK

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants