Skip to content

LifecyclePolicy

Source: src/AWS/OpenSearchServerless/LifecyclePolicy.ts

An Amazon OpenSearch Serverless data lifecycle policy. Retention lifecycle policies control how long documents are retained in the indexes matched by the policy’s resource patterns — OpenSearch Serverless automatically deletes documents older than the configured MinIndexRetention.

Lifecycle policies are free, provision instantly, and are matched to indexes by resource pattern (e.g. index/my-collection/*) — the collection does not need to exist when the policy is created.

Retain Log Indexes for 30 Days

import * as AWS from "alchemy/AWS";
const retention = yield* AWS.OpenSearchServerless.LifecyclePolicy("Retention", {
policyName: "logs-retention",
policy: {
Rules: [
{
ResourceType: "index",
Resource: ["index/logs/*"],
MinIndexRetention: "30d",
},
],
},
});

Unlimited Retention for Specific Indexes

const keepForever = yield* AWS.OpenSearchServerless.LifecyclePolicy("KeepForever", {
policyName: "audit-retention",
policy: {
Rules: [
{
ResourceType: "index",
Resource: ["index/audit/*"],
NoMinIndexRetention: true,
},
],
},
});