dlm

package
v1.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 31 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Data Lifecycle Manager

Parity grade: A · SDK aws-sdk-go-v2/service/dlm@v1.45.3 · last audited 2026-10-10 (ed6ef1a53)

Coverage

Metric Value
PARITY entries audited 8 (8 ok)
Feature families 1 (1 ok)
Known gaps none
Deferred items 0
Resource leaks clean

More

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrPolicyNotFound is returned when a lifecycle policy does not exist.
	ErrPolicyNotFound = awserr.New(errResourceNotFound, awserr.ErrNotFound)
	// ErrInvalidRequest is returned on invalid input.
	ErrInvalidRequest = awserr.New(errInvalidRequest, awserr.ErrInvalidParameter)
	// ErrLimitExceeded is returned by CreateLifecyclePolicy once the account
	// already holds maxPoliciesPerRegion policies in this Region -- AWS's
	// documented default "Policies per Region" quota (adjustable; quota code
	// L-5407D8DA, docs.aws.amazon.com/general/latest/gr/dlm.html).
	ErrLimitExceeded = awserr.New(errLimitExceeded, awserr.ErrInvalidParameter)
)
View Source
var ErrNilAppContext = errors.New("dlm: nil app context")

ErrNilAppContext is returned when Init is called with a nil AppContext.

View Source
var ErrResourceNotFound = errors.New("dlm: resource not found")

ErrResourceNotFound is returned by a ComputeService when the resource is already gone.

Functions

This section is empty.

Types

type ComputeService

type ComputeService interface {
	Targets(region, resourceType string) []Target
	CreateSnapshot(region, volumeID, description string, tags map[string]string) (string, error)
	CreateImage(region, instanceID, name, description string, tags map[string]string) (string, error)
	Exists(region, kind, id string) bool
	Delete(region, kind, id string) error
	// CopySnapshot copies a snapshot of srcRegion into dstRegion and tags the copy.
	CopySnapshot(
		srcRegion, dstRegion, snapshotID, description string, encrypted bool, kmsKey string, tags map[string]string,
	) (string, error)
	// CopyImage copies an AMI of srcRegion into dstRegion and tags the copy.
	CopyImage(
		srcRegion, dstRegion, imageID, name, description string, encrypted bool, kmsKey string, tags map[string]string,
	) (string, error)
	SetFastRestore(region, snapshotID string, zones []string, enable bool) error
	SetSnapshotSharing(region, snapshotID string, accounts []string, share bool) error
	ArchiveSnapshot(region, snapshotID string) error
	DeprecateImage(region, imageID string, at time.Time) error
}

ComputeService is the EC2 seam DLM drives: it lists targets and creates, tags and deletes snapshots and AMIs.

func NewEC2Compute

func NewEC2Compute(h *ec2backend.Handler) ComputeService

NewEC2Compute returns a ComputeService backed by the in-process EC2 handler, one backend per region.

type Handler

type Handler struct {
	Backend StorageBackend
	// contains filtered or unexported fields
}

Handler handles DLM HTTP requests.

func NewHandler

func NewHandler(b StorageBackend) *Handler

NewHandler constructs a new Handler.

func (*Handler) BackendFor

func (h *Handler) BackendFor(region string) StorageBackend

BackendFor returns the backend serving region: the home backend, or the sibling built on first use.

func (*Handler) EnableRegions

func (h *Handler) EnableRegions()

EnableRegions makes h serve every other region through lazily built per-region siblings.

func (*Handler) ExtractOperation

func (h *Handler) ExtractOperation(c *echo.Context) string

ExtractOperation extracts the operation name from the request.

func (*Handler) ExtractResource

func (h *Handler) ExtractResource(c *echo.Context) string

ExtractResource extracts the resource identifier from the request.

func (*Handler) GetSupportedOperations

func (h *Handler) GetSupportedOperations() []string

GetSupportedOperations returns the list of supported operations.

func (*Handler) Handler

func (h *Handler) Handler() echo.HandlerFunc

Handler returns the Echo handler function.

func (*Handler) MatchPriority

func (h *Handler) MatchPriority() int

MatchPriority returns the routing priority.

func (*Handler) Name

func (h *Handler) Name() string

Name returns the service name.

func (*Handler) OnSnapshotShared

func (h *Handler) OnSnapshotShared(ctx context.Context, evt ec2backend.SnapshotSharedEvent)

OnSnapshotShared routes an EC2 snapshot-shared event to the event-based policies of the snapshot's region.

func (*Handler) RegionBackends

func (h *Handler) RegionBackends() []StorageBackend

RegionBackends returns the home backend followed by every sibling built so far.

func (*Handler) RegionHandler

func (h *Handler) RegionHandler(region string) *Handler

RegionHandler returns the handler serving region: h itself for the home region, else its sibling.

func (*Handler) Reset

func (h *Handler) Reset()

Reset resets the backend.

func (*Handler) Restore

func (h *Handler) Restore(ctx context.Context, data []byte) error

Restore implements persistence.Persistable.

func (*Handler) RouteMatcher

func (h *Handler) RouteMatcher() service.Matcher

RouteMatcher returns a matcher that accepts DLM REST paths.

func (*Handler) SetCompute

func (h *Handler) SetCompute(c ComputeService)

SetCompute wires the EC2 seam into this region and every sibling built now or later.

func (*Handler) Shutdown

func (h *Handler) Shutdown(ctx context.Context)

Shutdown stops the scheduler of this handler and its regional siblings. Implements service.Shutdowner.

func (*Handler) Snapshot

func (h *Handler) Snapshot(ctx context.Context) []byte

Snapshot implements persistence.Persistable; other regions ride in an additive "regions" key.

func (*Handler) StartWorker

func (h *Handler) StartWorker(ctx context.Context) error

StartWorker starts the policy scheduler. Implements service.BackgroundWorker.

type InMemoryBackend

type InMemoryBackend struct {
	// contains filtered or unexported fields
}

InMemoryBackend implements StorageBackend using in-memory maps.

func NewInMemoryBackend

func NewInMemoryBackend(accountID, region string) *InMemoryBackend

NewInMemoryBackend constructs a new InMemoryBackend.

func (*InMemoryBackend) AccountID

func (b *InMemoryBackend) AccountID() string

AccountID returns the account ID.

func (*InMemoryBackend) CreateLifecyclePolicy

func (b *InMemoryBackend) CreateLifecyclePolicy(
	description, executionRoleARN, state string,
	tags map[string]string,
	policyDetails map[string]any,
) (*Policy, error)

CreateLifecyclePolicy creates a new lifecycle policy and returns it.

func (*InMemoryBackend) DeleteLifecyclePolicy

func (b *InMemoryBackend) DeleteLifecyclePolicy(policyID string) error

DeleteLifecyclePolicy removes a lifecycle policy.

func (*InMemoryBackend) GetLifecyclePolicies

func (b *InMemoryBackend) GetLifecyclePolicies(filter PolicyFilter) ([]*PolicySummary, error)

GetLifecyclePolicies returns summary info for lifecycle policies, optionally narrowed by filter (see PolicyFilter for the matching semantics).

func (*InMemoryBackend) GetLifecyclePolicy

func (b *InMemoryBackend) GetLifecyclePolicy(policyID string) (*Policy, error)

GetLifecyclePolicy returns full details for a lifecycle policy.

func (*InMemoryBackend) HandleSnapshotShared

func (b *InMemoryBackend) HandleSnapshotShared(ctx context.Context, now time.Time, evt ec2backend.SnapshotSharedEvent)

HandleSnapshotShared runs every ENABLED event-based policy whose EventSource matches evt.

func (*InMemoryBackend) InventoryResources

func (b *InMemoryBackend) InventoryResources() []TaggedEntry

InventoryResources lists every DLM policy, tagged or not.

func (*InMemoryBackend) ListTagsForResource

func (b *InMemoryBackend) ListTagsForResource(resourceARN string) (map[string]string, error)

ListTagsForResource returns tags for a DLM resource ARN.

func (*InMemoryBackend) Region

func (b *InMemoryBackend) Region() string

Region returns the region.

func (*InMemoryBackend) Reset

func (b *InMemoryBackend) Reset()

Reset clears all state.

func (*InMemoryBackend) Restore

func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error

Restore deserializes backend state from a snapshot. It implements persistence.Persistable.

func (*InMemoryBackend) RunSchedules

func (b *InMemoryBackend) RunSchedules(ctx context.Context, now time.Time)

RunSchedules creates and expires snapshots and AMIs for every ENABLED policy whose schedules fell due in (last evaluation, now]. DISABLED policies are skipped but their evaluation baseline still advances.

func (*InMemoryBackend) SetCompute

func (b *InMemoryBackend) SetCompute(c ComputeService)

SetCompute wires the EC2 seam; without it schedules are evaluated but nothing is created.

func (*InMemoryBackend) Snapshot

func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte

Snapshot serializes the backend state to JSON. It implements persistence.Persistable.

func (*InMemoryBackend) TagResource

func (b *InMemoryBackend) TagResource(resourceARN string, tags map[string]string) error

TagResource applies tags to a DLM resource ARN.

func (*InMemoryBackend) TaggedResources added in v1.3.1

func (b *InMemoryBackend) TaggedResources() []TaggedEntry

TaggedResources lists every DLM policy that carries at least one tag.

func (*InMemoryBackend) UntagResource

func (b *InMemoryBackend) UntagResource(resourceARN string, tagKeys []string) error

UntagResource removes tags from a DLM resource ARN.

func (*InMemoryBackend) UpdateLifecyclePolicy

func (b *InMemoryBackend) UpdateLifecyclePolicy(
	policyID string, description, executionRoleARN *string, state string,
	policyDetails map[string]any, defaultPolicyOverrides map[string]any,
) error

UpdateLifecyclePolicy updates mutable fields of an existing policy.

description and executionRoleARN follow presence semantics, not truthiness: nil means the field was omitted from the request (leave unchanged), a non-nil pointer to "" means the caller explicitly cleared it. See the StorageBackend.UpdateLifecyclePolicy doc comment for why.

type Policy

type Policy struct {
	DateCreated      time.Time
	DateModified     time.Time
	Tags             map[string]string
	PolicyDetails    map[string]any
	Description      string
	ExecutionRoleARN string
	PolicyArn        string
	PolicyID         string
	State            string
	StatusMessage    string
	DefaultPolicy    bool
}

Policy holds full lifecycle policy details. time.Time fields are first so their non-pointer prefix reduces GC pointer bytes.

type PolicyFilter

type PolicyFilter struct {
	State string
	// DefaultPolicyType narrows results to default policies only: "VOLUME"
	// (EBS snapshot default policy), "INSTANCE" (EBS-backed AMI default
	// policy), or "ALL" (any default policy). Empty imposes no restriction
	// (both custom and default policies match).
	DefaultPolicyType string
	PolicyIDs         []string
	// ResourceTypes matches against PolicyDetails.ResourceTypes.
	ResourceTypes []string
	// TargetTags holds "key=value" pairs matched against
	// PolicyDetails.TargetTags.
	TargetTags []string
	// TagsToAdd holds "key=value" pairs matched against the TagsToAdd of any
	// of PolicyDetails.Schedules.
	TagsToAdd []string
}

PolicyFilter narrows the results of GetLifecyclePolicies. A zero-value field (nil slice or empty string) imposes no restriction along that dimension. Matching AWS's documented semantics for the GetLifecyclePolicies query parameters, PolicyIDs/ResourceTypes/TargetTags/ TagsToAdd each apply an ANY-of match within the list, and the dimensions are ANDed together.

type PolicySummary

type PolicySummary struct {
	Tags          map[string]string
	PolicyID      string
	Description   string
	State         string
	PolicyType    string
	DefaultPolicy bool
}

PolicySummary holds summary lifecycle policy info.

type Provider

type Provider struct{}

Provider implements service.Provider for Amazon DLM.

func (*Provider) Init

Init initializes the DLM service backend and handler.

func (*Provider) Name

func (p *Provider) Name() string

Name returns the provider name.

type Scheduler

type Scheduler struct {
	// contains filtered or unexported fields
}

Scheduler evaluates policy schedules on a ticker.

func NewScheduler

func NewScheduler(backend *InMemoryBackend, tick time.Duration) *Scheduler

NewScheduler returns a scheduler for backend; a zero tick uses the default.

func (*Scheduler) Run

func (s *Scheduler) Run(ctx context.Context)

Run implements worker.Runner.

type StorageBackend

type StorageBackend interface {
	CreateLifecyclePolicy(
		description, executionRoleARN, state string, tags map[string]string, policyDetails map[string]any,
	) (*Policy, error)
	DeleteLifecyclePolicy(policyID string) error
	GetLifecyclePolicies(filter PolicyFilter) ([]*PolicySummary, error)
	GetLifecyclePolicy(policyID string) (*Policy, error)
	// description and executionRoleARN are *string, not string, because the
	// real UpdateLifecyclePolicyInput carries them as pointers: a nil pointer
	// means the field was omitted from the request body (no change), while a
	// non-nil pointer to "" means the caller explicitly sent an empty string
	// (clear the field). A plain string parameter cannot distinguish those
	// two wire states. State stays a plain string because
	// SettablePolicyStateValues is a non-pointer value type on the wire (the
	// real SDK's serializer only ever emits it `if len(State) > 0`, so an
	// explicit empty State is not constructible even by the real SDK).
	//
	// defaultPolicyOverrides carries the top-level [Default policies only]
	// request fields (see defaultPolicyFields), PolicyDetails-keyed. It must
	// be applied under the same lock as the rest of the update: when
	// policyDetails is nil the overrides target the policy's EXISTING stored
	// PolicyDetails, so merging in the handler instead would race a
	// concurrent update.
	UpdateLifecyclePolicy(
		policyID string, description, executionRoleARN *string, state string,
		policyDetails map[string]any, defaultPolicyOverrides map[string]any,
	) error

	TagResource(resourceARN string, tags map[string]string) error
	UntagResource(resourceARN string, tagKeys []string) error
	ListTagsForResource(resourceARN string) (map[string]string, error)

	AccountID() string
	Region() string
	Reset()
	Snapshot(ctx context.Context) []byte
	Restore(ctx context.Context, data []byte) error
}

StorageBackend is the interface for DLM storage operations.

type TaggedEntry added in v1.3.1

type TaggedEntry struct {
	Tags map[string]string
	ARN  string
}

TaggedEntry pairs a resource ARN with its tags.

type Target

type Target struct {
	Tags       map[string]string
	ID         string
	VolumeType string
	InstanceID string
	VolumeIDs  []string
	Boot       bool
}

Target is a volume or instance a policy can act on.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL