Skip to content

AWS.Rbin reference

Source: src/AWS/Rbin/GetRule.ts

Runtime binding for rbin:GetRule.

Reads the bound retention Rule’s full detail — retention period, resource type, resource/exclusion tags, lock state, and status — so a function can audit its Recycle Bin coverage or alert on an unexpected unlock at runtime. The rule’s identifier is injected from the binding. Provide the implementation with Effect.provide(AWS.Rbin.GetRuleHttp).

// init — grants rbin:GetRule on the rule's ARN
const getRule = yield* AWS.Rbin.GetRule(rule);
// runtime
const detail = yield* getRule();
yield* Effect.log(
`rule ${detail.Identifier} retains ${detail.ResourceType} for ` +
`${detail.RetentionPeriod?.RetentionPeriodValue} days (${detail.LockState ?? "unlocked"})`,
);

Source: src/AWS/Rbin/ListRules.ts

Runtime binding for rbin:ListRules.

Enumerates the Region’s Recycle Bin retention rules for a resource type (EBS_SNAPSHOT, EC2_IMAGE, or EBS_VOLUME), optionally filtered by resource tags, exclusion tags, or lock state — so a function can verify that deletion protection is in place before destructive maintenance. ListRules is an account-level list action, so the grant is on *. Provide the implementation with Effect.provide(AWS.Rbin.ListRulesHttp).

// init — grants rbin:ListRules on *
const listRules = yield* AWS.Rbin.ListRules();
// runtime
const { Rules } = yield* listRules({ ResourceType: "EBS_SNAPSHOT" });
for (const rule of Rules ?? []) {
yield* Effect.log(`${rule.Identifier}: ${rule.Description ?? ""}`);
}

Source: src/AWS/Rbin/Rule.ts

A Recycle Bin retention rule. Recycle Bin retains deleted EBS snapshots, EBS-backed AMIs, and EBS volumes for a configurable period so they can be recovered after accidental deletion.

Rules are either tag-level (retain only resources carrying specific resource tags) or Region-level (retain every resource of the type in the Region, optionally minus exclusion tags). Changing resourceType replaces the rule; every other property updates in place.

Tag-level rule for EBS snapshots

import * as Rbin from "alchemy/AWS/Rbin";
const rule = yield* Rbin.Rule("SnapshotRetention", {
resourceType: "EBS_SNAPSHOT",
retentionPeriod: "7 days",
description: "Retain tagged snapshots for 7 days",
resourceTags: [{ key: "team", value: "data" }],
});

Region-level rule for AMIs

const rule = yield* Rbin.Rule("AmiRetention", {
resourceType: "EC2_IMAGE",
retentionPeriod: "14 days",
description: "Retain all deregistered AMIs in this Region",
});

Region-level rule with exclusion tags

const rule = yield* Rbin.Rule("SnapshotRetention", {
resourceType: "EBS_SNAPSHOT",
retentionPeriod: "30 days",
excludeResourceTags: [{ key: "ephemeral", value: "true" }],
});

A Region-level rule (without exclusion tags) can be locked so it cannot be modified or deleted. Removing lockConfiguration unlocks the rule, which stays protected in pending_unlock until the unlock delay expires.

const rule = yield* Rbin.Rule("LockedRetention", {
resourceType: "EBS_SNAPSHOT",
retentionPeriod: "30 days",
lockConfiguration: { unlockDelay: "7 days" },
});
const rule = yield* Rbin.Rule("SnapshotRetention", {
resourceType: "EBS_SNAPSHOT",
retentionPeriod: "7 days",
resourceTags: [{ key: "team", value: "data" }],
tags: { CostCenter: "storage" },
});