Amazon Data Lifecycle Manager examples using Amazon CLI
The following code examples show you how to perform actions and implement common scenarios by using the Amazon Command Line Interface with Amazon Data Lifecycle Manager.
Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.
Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.
Topics
Actions
The following code example shows how to use create-default-role.
- Amazon CLI
-
To create the required IAM role for Amazon DLM
The following
dlm create-default-roleexample creates the AmazonDataLifecycleManagerDefaultRole default role for managing snapshots.aws dlm create-default-role \ --resource-typesnapshotThis command produces no output.
For more information, see Default service roles for Amazon Data Lifecycle Manager
in the Amazon Elastic Compute Cloud User Guide. -
For API details, see CreateDefaultRole
in Amazon CLI Command Reference.
-
The following code example shows how to use create-lifecycle-policy.
- Amazon CLI
-
To create a lifecycle policy
The following
create-lifecycle-policyexample creates a lifecycle policy that creates a daily snapshot of volumes at the specified time. The specified tags are added to the snapshots, and tags are also copied from the volume and added to the snapshots. If creating a new snapshot exceeds the specified maximum count, the oldest snapshot is deleted.aws dlm create-lifecycle-policy \ --description"My first policy"\ --stateENABLED\ --execution-role-arnarn:aws:iam::12345678910:role/AWSDataLifecycleManagerDefaultRole\ --policy-detailsfile://policyDetails.jsonContents of
policyDetails.json:{ "ResourceTypes": [ "VOLUME" ], "TargetTags": [ { "Key": "costCenter", "Value": "115" } ], "Schedules":[ { "Name": "DailySnapshots", "CopyTags": true, "TagsToAdd": [ { "Key": "type", "Value": "myDailySnapshot" } ], "CreateRule": { "Interval": 24, "IntervalUnit": "HOURS", "Times": [ "03:00" ] }, "RetainRule": { "Count":5 } } ] }Output:
{ "PolicyId": "policy-0123456789abcdef0" }-
For API details, see CreateLifecyclePolicy
in Amazon CLI Command Reference.
-
The following code example shows how to use delete-lifecycle-policy.
- Amazon CLI
-
To delete a lifecycle policy
The following example deletes the specified lifecycle policy.:
aws dlm delete-lifecycle-policy --policy-idpolicy-0123456789abcdef0-
For API details, see DeleteLifecyclePolicy
in Amazon CLI Command Reference.
-
The following code example shows how to use get-lifecycle-policies.
- Amazon CLI
-
To get a summary of your lifecycle policies
The following
get-lifecycle-policiesexample lists all of your lifecycle policies.aws dlm get-lifecycle-policiesOutput:
{ "Policies": [ { "PolicyId": "policy-0123456789abcdef0", "Description": "My first policy", "State": "ENABLED" } ] }-
For API details, see GetLifecyclePolicies
in Amazon CLI Command Reference.
-
The following code example shows how to use get-lifecycle-policy.
- Amazon CLI
-
To describe a lifecycle policy
The following
get-lifecycle-policyexample displays details for the specified lifecycle policy.aws dlm get-lifecycle-policy \ --policy-idpolicy-0123456789abcdef0Output:
{ "Policy": { "PolicyId": "policy-0123456789abcdef0", "Description": "My policy", "State": "ENABLED", "ExecutionRoleArn": "arn:aws:iam::123456789012:role/AWSDataLifecycleManagerDefaultRole", "DateCreated": "2019-08-08T17:45:42Z", "DateModified": "2019-08-08T17:45:42Z", "PolicyDetails": { "PolicyType": "EBS_SNAPSHOT_MANAGEMENT", "ResourceTypes": [ "VOLUME" ], "TargetTags": [ { "Key": "costCenter", "Value": "115" } ], "Schedules": [ { "Name": "DailySnapshots", "CopyTags": true, "TagsToAdd": [ { "Key": "type", "Value": "myDailySnapshot" } ], "CreateRule": { "Interval": 24, "IntervalUnit": "HOURS", "Times": [ "03:00" ] }, "RetainRule": { "Count": 5 } } ] } } }-
For API details, see GetLifecyclePolicy
in Amazon CLI Command Reference.
-
The following code example shows how to use update-lifecycle-policy.
- Amazon CLI
-
Example 1: To enable a lifecycle policy
The following
update-lifecycle-policyexample enables the specified lifecycle policy.aws dlm update-lifecycle-policy \ --policy-idpolicy-0123456789abcdef0\ --stateENABLEDExample 2: To disable a lifecycle policy
The following
update-lifecycle-policyexample disables the specified lifecycle policy.aws dlm update-lifecycle-policy \ --policy-idpolicy-0123456789abcdef0\ --stateDISABLEDExample 3: To update the details for lifecycle policy
The following
update-lifecycle-policyexample updates the target tags for the specified lifecycle policy.aws dlm update-lifecycle-policy \ --policy-idpolicy-0123456789abcdef0--policy-detailsfile://policyDetails.jsonContents of
policyDetails.json. Other details not referenced in this file are not changed by the command.{ "TargetTags": [ { "Key": "costCenter", "Value": "120" }, { "Key": "project", "Value": "lima" } ] }-
For API details, see UpdateLifecyclePolicy
in Amazon CLI Command Reference.
-