AWS v6.71.0 published on Friday, Mar 7, 2025 by Pulumi
aws.ecr.getLifecyclePolicyDocument
Explore with Pulumi AI
Generates an ECR lifecycle policy document in JSON format. Can be used with resources such as the aws.ecr.LifecyclePolicy resource.
For more information about building AWS ECR lifecycle policy documents, see the AWS ECR Lifecycle Policy Document Guide.
Example Usage
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const example = aws.ecr.getLifecyclePolicyDocument({
    rules: [{
        priority: 1,
        description: "This is a test.",
        selection: {
            tagStatus: "tagged",
            tagPrefixLists: ["prod"],
            countType: "imageCountMoreThan",
            countNumber: 100,
        },
    }],
});
const exampleLifecyclePolicy = new aws.ecr.LifecyclePolicy("example", {
    repository: exampleAwsEcrRepository.name,
    policy: example.then(example => example.json),
});
import pulumi
import pulumi_aws as aws
example = aws.ecr.get_lifecycle_policy_document(rules=[{
    "priority": 1,
    "description": "This is a test.",
    "selection": {
        "tag_status": "tagged",
        "tag_prefix_lists": ["prod"],
        "count_type": "imageCountMoreThan",
        "count_number": 100,
    },
}])
example_lifecycle_policy = aws.ecr.LifecyclePolicy("example",
    repository=example_aws_ecr_repository["name"],
    policy=example.json)
package main
import (
	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ecr"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		example, err := ecr.GetLifecyclePolicyDocument(ctx, &ecr.GetLifecyclePolicyDocumentArgs{
			Rules: []ecr.GetLifecyclePolicyDocumentRule{
				{
					Priority:    1,
					Description: pulumi.StringRef("This is a test."),
					Selection: {
						TagStatus: "tagged",
						TagPrefixLists: []string{
							"prod",
						},
						CountType:   "imageCountMoreThan",
						CountNumber: 100,
					},
				},
			},
		}, nil)
		if err != nil {
			return err
		}
		_, err = ecr.NewLifecyclePolicy(ctx, "example", &ecr.LifecyclePolicyArgs{
			Repository: pulumi.Any(exampleAwsEcrRepository.Name),
			Policy:     pulumi.String(example.Json),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() => 
{
    var example = Aws.Ecr.GetLifecyclePolicyDocument.Invoke(new()
    {
        Rules = new[]
        {
            new Aws.Ecr.Inputs.GetLifecyclePolicyDocumentRuleInputArgs
            {
                Priority = 1,
                Description = "This is a test.",
                Selection = new Aws.Ecr.Inputs.GetLifecyclePolicyDocumentRuleSelectionInputArgs
                {
                    TagStatus = "tagged",
                    TagPrefixLists = new[]
                    {
                        "prod",
                    },
                    CountType = "imageCountMoreThan",
                    CountNumber = 100,
                },
            },
        },
    });
    var exampleLifecyclePolicy = new Aws.Ecr.LifecyclePolicy("example", new()
    {
        Repository = exampleAwsEcrRepository.Name,
        Policy = example.Apply(getLifecyclePolicyDocumentResult => getLifecyclePolicyDocumentResult.Json),
    });
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.ecr.EcrFunctions;
import com.pulumi.aws.ecr.inputs.GetLifecyclePolicyDocumentArgs;
import com.pulumi.aws.ecr.LifecyclePolicy;
import com.pulumi.aws.ecr.LifecyclePolicyArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }
    public static void stack(Context ctx) {
        final var example = EcrFunctions.getLifecyclePolicyDocument(GetLifecyclePolicyDocumentArgs.builder()
            .rules(GetLifecyclePolicyDocumentRuleArgs.builder()
                .priority(1)
                .description("This is a test.")
                .selection(GetLifecyclePolicyDocumentRuleSelectionArgs.builder()
                    .tagStatus("tagged")
                    .tagPrefixLists("prod")
                    .countType("imageCountMoreThan")
                    .countNumber(100)
                    .build())
                .build())
            .build());
        var exampleLifecyclePolicy = new LifecyclePolicy("exampleLifecyclePolicy", LifecyclePolicyArgs.builder()
            .repository(exampleAwsEcrRepository.name())
            .policy(example.applyValue(getLifecyclePolicyDocumentResult -> getLifecyclePolicyDocumentResult.json()))
            .build());
    }
}
resources:
  exampleLifecyclePolicy:
    type: aws:ecr:LifecyclePolicy
    name: example
    properties:
      repository: ${exampleAwsEcrRepository.name}
      policy: ${example.json}
variables:
  example:
    fn::invoke:
      function: aws:ecr:getLifecyclePolicyDocument
      arguments:
        rules:
          - priority: 1
            description: This is a test.
            selection:
              tagStatus: tagged
              tagPrefixLists:
                - prod
              countType: imageCountMoreThan
              countNumber: 100
Using getLifecyclePolicyDocument
Two invocation forms are available. The direct form accepts plain arguments and either blocks until the result value is available, or returns a Promise-wrapped result. The output form accepts Input-wrapped arguments and returns an Output-wrapped result.
function getLifecyclePolicyDocument(args: GetLifecyclePolicyDocumentArgs, opts?: InvokeOptions): Promise<GetLifecyclePolicyDocumentResult>
function getLifecyclePolicyDocumentOutput(args: GetLifecyclePolicyDocumentOutputArgs, opts?: InvokeOptions): Output<GetLifecyclePolicyDocumentResult>def get_lifecycle_policy_document(rules: Optional[Sequence[GetLifecyclePolicyDocumentRule]] = None,
                                  opts: Optional[InvokeOptions] = None) -> GetLifecyclePolicyDocumentResult
def get_lifecycle_policy_document_output(rules: Optional[pulumi.Input[Sequence[pulumi.Input[GetLifecyclePolicyDocumentRuleArgs]]]] = None,
                                  opts: Optional[InvokeOptions] = None) -> Output[GetLifecyclePolicyDocumentResult]func GetLifecyclePolicyDocument(ctx *Context, args *GetLifecyclePolicyDocumentArgs, opts ...InvokeOption) (*GetLifecyclePolicyDocumentResult, error)
func GetLifecyclePolicyDocumentOutput(ctx *Context, args *GetLifecyclePolicyDocumentOutputArgs, opts ...InvokeOption) GetLifecyclePolicyDocumentResultOutput> Note: This function is named GetLifecyclePolicyDocument in the Go SDK.
public static class GetLifecyclePolicyDocument 
{
    public static Task<GetLifecyclePolicyDocumentResult> InvokeAsync(GetLifecyclePolicyDocumentArgs args, InvokeOptions? opts = null)
    public static Output<GetLifecyclePolicyDocumentResult> Invoke(GetLifecyclePolicyDocumentInvokeArgs args, InvokeOptions? opts = null)
}public static CompletableFuture<GetLifecyclePolicyDocumentResult> getLifecyclePolicyDocument(GetLifecyclePolicyDocumentArgs args, InvokeOptions options)
public static Output<GetLifecyclePolicyDocumentResult> getLifecyclePolicyDocument(GetLifecyclePolicyDocumentArgs args, InvokeOptions options)
fn::invoke:
  function: aws:ecr/getLifecyclePolicyDocument:getLifecyclePolicyDocument
  arguments:
    # arguments dictionaryThe following arguments are supported:
getLifecyclePolicyDocument Result
The following output properties are available:
- Id string
- The provider-assigned unique ID for this managed resource.
- Json string
- The above arguments serialized as a standard JSON policy document.
- Rules
List<GetLifecycle Policy Document Rule> 
- Id string
- The provider-assigned unique ID for this managed resource.
- Json string
- The above arguments serialized as a standard JSON policy document.
- Rules
[]GetLifecycle Policy Document Rule 
- id String
- The provider-assigned unique ID for this managed resource.
- json String
- The above arguments serialized as a standard JSON policy document.
- rules
List<GetLifecycle Policy Document Rule> 
- id string
- The provider-assigned unique ID for this managed resource.
- json string
- The above arguments serialized as a standard JSON policy document.
- rules
GetLifecycle Policy Document Rule[] 
- id str
- The provider-assigned unique ID for this managed resource.
- json str
- The above arguments serialized as a standard JSON policy document.
- rules
Sequence[GetLifecycle Policy Document Rule] 
- id String
- The provider-assigned unique ID for this managed resource.
- json String
- The above arguments serialized as a standard JSON policy document.
- rules List<Property Map>
Supporting Types
GetLifecyclePolicyDocumentRule    
- Priority int
- Sets the order in which rules are evaluated, lowest to highest. When you add rules to a lifecycle policy, you must give them each a unique value for priority. Values do not need to be sequential across rules in a policy. A rule with atag_statusvalue of "any" must have the highest value forpriorityand be evaluated last.
- Action
GetLifecycle Policy Document Rule Action 
- Specifies the action type.
- Description string
- Describes the purpose of a rule within a lifecycle policy.
- Selection
GetLifecycle Policy Document Rule Selection 
- Collects parameters describing the selection criteria for the ECR lifecycle policy:
- Priority int
- Sets the order in which rules are evaluated, lowest to highest. When you add rules to a lifecycle policy, you must give them each a unique value for priority. Values do not need to be sequential across rules in a policy. A rule with atag_statusvalue of "any" must have the highest value forpriorityand be evaluated last.
- Action
GetLifecycle Policy Document Rule Action 
- Specifies the action type.
- Description string
- Describes the purpose of a rule within a lifecycle policy.
- Selection
GetLifecycle Policy Document Rule Selection 
- Collects parameters describing the selection criteria for the ECR lifecycle policy:
- priority Integer
- Sets the order in which rules are evaluated, lowest to highest. When you add rules to a lifecycle policy, you must give them each a unique value for priority. Values do not need to be sequential across rules in a policy. A rule with atag_statusvalue of "any" must have the highest value forpriorityand be evaluated last.
- action
GetLifecycle Policy Document Rule Action 
- Specifies the action type.
- description String
- Describes the purpose of a rule within a lifecycle policy.
- selection
GetLifecycle Policy Document Rule Selection 
- Collects parameters describing the selection criteria for the ECR lifecycle policy:
- priority number
- Sets the order in which rules are evaluated, lowest to highest. When you add rules to a lifecycle policy, you must give them each a unique value for priority. Values do not need to be sequential across rules in a policy. A rule with atag_statusvalue of "any" must have the highest value forpriorityand be evaluated last.
- action
GetLifecycle Policy Document Rule Action 
- Specifies the action type.
- description string
- Describes the purpose of a rule within a lifecycle policy.
- selection
GetLifecycle Policy Document Rule Selection 
- Collects parameters describing the selection criteria for the ECR lifecycle policy:
- priority int
- Sets the order in which rules are evaluated, lowest to highest. When you add rules to a lifecycle policy, you must give them each a unique value for priority. Values do not need to be sequential across rules in a policy. A rule with atag_statusvalue of "any" must have the highest value forpriorityand be evaluated last.
- action
GetLifecycle Policy Document Rule Action 
- Specifies the action type.
- description str
- Describes the purpose of a rule within a lifecycle policy.
- selection
GetLifecycle Policy Document Rule Selection 
- Collects parameters describing the selection criteria for the ECR lifecycle policy:
- priority Number
- Sets the order in which rules are evaluated, lowest to highest. When you add rules to a lifecycle policy, you must give them each a unique value for priority. Values do not need to be sequential across rules in a policy. A rule with atag_statusvalue of "any" must have the highest value forpriorityand be evaluated last.
- action Property Map
- Specifies the action type.
- description String
- Describes the purpose of a rule within a lifecycle policy.
- selection Property Map
- Collects parameters describing the selection criteria for the ECR lifecycle policy:
GetLifecyclePolicyDocumentRuleAction     
- Type string
- The supported value is expire.
- Type string
- The supported value is expire.
- type String
- The supported value is expire.
- type string
- The supported value is expire.
- type str
- The supported value is expire.
- type String
- The supported value is expire.
GetLifecyclePolicyDocumentRuleSelection     
- CountNumber int
- Specify a count number. If the count_typeused is "imageCountMoreThan", then the value is the maximum number of images that you want to retain in your repository. If thecount_typeused is "sinceImagePushed", then the value is the maximum age limit for your images.
- CountType string
- Specify a count type to apply to the images. If count_typeis set to "imageCountMoreThan", you also specifycount_numberto create a rule that sets a limit on the number of images that exist in your repository. Ifcount_typeis set to "sinceImagePushed", you also specifycount_unitandcount_numberto specify a time limit on the images that exist in your repository.
- string
- Determines whether the lifecycle policy rule that you are adding specifies a tag for an image. Acceptable options are "tagged", "untagged", or "any". If you specify "any", then all images have the rule applied to them. If you specify "tagged", then you must also specify a tag_prefix_listvalue. If you specify "untagged", then you must omittag_prefix_list.
- CountUnit string
- Specify a count unit of days to indicate that as the unit of time, in addition to count_number, which is the number of days.
- TagPattern List<string>Lists 
- You must specify a comma-separated list of image tag patterns that may contain wildcards (*) on which to take action with your lifecycle policy. For example, if your images are tagged as prod,prod1,prod2, and so on, you would use the tag pattern list["prod\*"]to specify all of them. If you specify multiple tags, only the images with all specified tags are selected. There is a maximum limit of four wildcards (*) per string. For example,["*test*1*2*3", "test*1*2*3*"]is valid but["test*1*2*3*4*5*6"]is invalid.
- TagPrefix List<string>Lists 
- You must specify a comma-separated list of image tag prefixes on which to take action with your lifecycle policy. For example, if your images are tagged as prod,prod1,prod2, and so on, you would use the tag prefix "prod" to specify all of them. If you specify multiple tags, only images with all specified tags are selected.
- CountNumber int
- Specify a count number. If the count_typeused is "imageCountMoreThan", then the value is the maximum number of images that you want to retain in your repository. If thecount_typeused is "sinceImagePushed", then the value is the maximum age limit for your images.
- CountType string
- Specify a count type to apply to the images. If count_typeis set to "imageCountMoreThan", you also specifycount_numberto create a rule that sets a limit on the number of images that exist in your repository. Ifcount_typeis set to "sinceImagePushed", you also specifycount_unitandcount_numberto specify a time limit on the images that exist in your repository.
- string
- Determines whether the lifecycle policy rule that you are adding specifies a tag for an image. Acceptable options are "tagged", "untagged", or "any". If you specify "any", then all images have the rule applied to them. If you specify "tagged", then you must also specify a tag_prefix_listvalue. If you specify "untagged", then you must omittag_prefix_list.
- CountUnit string
- Specify a count unit of days to indicate that as the unit of time, in addition to count_number, which is the number of days.
- TagPattern []stringLists 
- You must specify a comma-separated list of image tag patterns that may contain wildcards (*) on which to take action with your lifecycle policy. For example, if your images are tagged as prod,prod1,prod2, and so on, you would use the tag pattern list["prod\*"]to specify all of them. If you specify multiple tags, only the images with all specified tags are selected. There is a maximum limit of four wildcards (*) per string. For example,["*test*1*2*3", "test*1*2*3*"]is valid but["test*1*2*3*4*5*6"]is invalid.
- TagPrefix []stringLists 
- You must specify a comma-separated list of image tag prefixes on which to take action with your lifecycle policy. For example, if your images are tagged as prod,prod1,prod2, and so on, you would use the tag prefix "prod" to specify all of them. If you specify multiple tags, only images with all specified tags are selected.
- countNumber Integer
- Specify a count number. If the count_typeused is "imageCountMoreThan", then the value is the maximum number of images that you want to retain in your repository. If thecount_typeused is "sinceImagePushed", then the value is the maximum age limit for your images.
- countType String
- Specify a count type to apply to the images. If count_typeis set to "imageCountMoreThan", you also specifycount_numberto create a rule that sets a limit on the number of images that exist in your repository. Ifcount_typeis set to "sinceImagePushed", you also specifycount_unitandcount_numberto specify a time limit on the images that exist in your repository.
- String
- Determines whether the lifecycle policy rule that you are adding specifies a tag for an image. Acceptable options are "tagged", "untagged", or "any". If you specify "any", then all images have the rule applied to them. If you specify "tagged", then you must also specify a tag_prefix_listvalue. If you specify "untagged", then you must omittag_prefix_list.
- countUnit String
- Specify a count unit of days to indicate that as the unit of time, in addition to count_number, which is the number of days.
- tagPattern List<String>Lists 
- You must specify a comma-separated list of image tag patterns that may contain wildcards (*) on which to take action with your lifecycle policy. For example, if your images are tagged as prod,prod1,prod2, and so on, you would use the tag pattern list["prod\*"]to specify all of them. If you specify multiple tags, only the images with all specified tags are selected. There is a maximum limit of four wildcards (*) per string. For example,["*test*1*2*3", "test*1*2*3*"]is valid but["test*1*2*3*4*5*6"]is invalid.
- tagPrefix List<String>Lists 
- You must specify a comma-separated list of image tag prefixes on which to take action with your lifecycle policy. For example, if your images are tagged as prod,prod1,prod2, and so on, you would use the tag prefix "prod" to specify all of them. If you specify multiple tags, only images with all specified tags are selected.
- countNumber number
- Specify a count number. If the count_typeused is "imageCountMoreThan", then the value is the maximum number of images that you want to retain in your repository. If thecount_typeused is "sinceImagePushed", then the value is the maximum age limit for your images.
- countType string
- Specify a count type to apply to the images. If count_typeis set to "imageCountMoreThan", you also specifycount_numberto create a rule that sets a limit on the number of images that exist in your repository. Ifcount_typeis set to "sinceImagePushed", you also specifycount_unitandcount_numberto specify a time limit on the images that exist in your repository.
- string
- Determines whether the lifecycle policy rule that you are adding specifies a tag for an image. Acceptable options are "tagged", "untagged", or "any". If you specify "any", then all images have the rule applied to them. If you specify "tagged", then you must also specify a tag_prefix_listvalue. If you specify "untagged", then you must omittag_prefix_list.
- countUnit string
- Specify a count unit of days to indicate that as the unit of time, in addition to count_number, which is the number of days.
- tagPattern string[]Lists 
- You must specify a comma-separated list of image tag patterns that may contain wildcards (*) on which to take action with your lifecycle policy. For example, if your images are tagged as prod,prod1,prod2, and so on, you would use the tag pattern list["prod\*"]to specify all of them. If you specify multiple tags, only the images with all specified tags are selected. There is a maximum limit of four wildcards (*) per string. For example,["*test*1*2*3", "test*1*2*3*"]is valid but["test*1*2*3*4*5*6"]is invalid.
- tagPrefix string[]Lists 
- You must specify a comma-separated list of image tag prefixes on which to take action with your lifecycle policy. For example, if your images are tagged as prod,prod1,prod2, and so on, you would use the tag prefix "prod" to specify all of them. If you specify multiple tags, only images with all specified tags are selected.
- count_number int
- Specify a count number. If the count_typeused is "imageCountMoreThan", then the value is the maximum number of images that you want to retain in your repository. If thecount_typeused is "sinceImagePushed", then the value is the maximum age limit for your images.
- count_type str
- Specify a count type to apply to the images. If count_typeis set to "imageCountMoreThan", you also specifycount_numberto create a rule that sets a limit on the number of images that exist in your repository. Ifcount_typeis set to "sinceImagePushed", you also specifycount_unitandcount_numberto specify a time limit on the images that exist in your repository.
- tag_status str
- Determines whether the lifecycle policy rule that you are adding specifies a tag for an image. Acceptable options are "tagged", "untagged", or "any". If you specify "any", then all images have the rule applied to them. If you specify "tagged", then you must also specify a tag_prefix_listvalue. If you specify "untagged", then you must omittag_prefix_list.
- count_unit str
- Specify a count unit of days to indicate that as the unit of time, in addition to count_number, which is the number of days.
- tag_pattern_ Sequence[str]lists 
- You must specify a comma-separated list of image tag patterns that may contain wildcards (*) on which to take action with your lifecycle policy. For example, if your images are tagged as prod,prod1,prod2, and so on, you would use the tag pattern list["prod\*"]to specify all of them. If you specify multiple tags, only the images with all specified tags are selected. There is a maximum limit of four wildcards (*) per string. For example,["*test*1*2*3", "test*1*2*3*"]is valid but["test*1*2*3*4*5*6"]is invalid.
- tag_prefix_ Sequence[str]lists 
- You must specify a comma-separated list of image tag prefixes on which to take action with your lifecycle policy. For example, if your images are tagged as prod,prod1,prod2, and so on, you would use the tag prefix "prod" to specify all of them. If you specify multiple tags, only images with all specified tags are selected.
- countNumber Number
- Specify a count number. If the count_typeused is "imageCountMoreThan", then the value is the maximum number of images that you want to retain in your repository. If thecount_typeused is "sinceImagePushed", then the value is the maximum age limit for your images.
- countType String
- Specify a count type to apply to the images. If count_typeis set to "imageCountMoreThan", you also specifycount_numberto create a rule that sets a limit on the number of images that exist in your repository. Ifcount_typeis set to "sinceImagePushed", you also specifycount_unitandcount_numberto specify a time limit on the images that exist in your repository.
- String
- Determines whether the lifecycle policy rule that you are adding specifies a tag for an image. Acceptable options are "tagged", "untagged", or "any". If you specify "any", then all images have the rule applied to them. If you specify "tagged", then you must also specify a tag_prefix_listvalue. If you specify "untagged", then you must omittag_prefix_list.
- countUnit String
- Specify a count unit of days to indicate that as the unit of time, in addition to count_number, which is the number of days.
- tagPattern List<String>Lists 
- You must specify a comma-separated list of image tag patterns that may contain wildcards (*) on which to take action with your lifecycle policy. For example, if your images are tagged as prod,prod1,prod2, and so on, you would use the tag pattern list["prod\*"]to specify all of them. If you specify multiple tags, only the images with all specified tags are selected. There is a maximum limit of four wildcards (*) per string. For example,["*test*1*2*3", "test*1*2*3*"]is valid but["test*1*2*3*4*5*6"]is invalid.
- tagPrefix List<String>Lists 
- You must specify a comma-separated list of image tag prefixes on which to take action with your lifecycle policy. For example, if your images are tagged as prod,prod1,prod2, and so on, you would use the tag prefix "prod" to specify all of them. If you specify multiple tags, only images with all specified tags are selected.
Package Details
- Repository
- AWS Classic pulumi/pulumi-aws
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the awsTerraform Provider.