- Newest
- Most votes
- Most comments
I finally figured it out. Create EventBridge rule with the following event pattern.
{
"source": ["aws.ec2"],
"detail-type": ["AWS API Call via CloudTrail"],
"detail": {
"eventSource": ["ec2.amazonaws.com"],
"eventName": ["CreateSnapshots"]
}
}
While Amazon Data Lifecycle Manager (DLM) does not directly support dynamic naming of snapshots through console configuration, you can achieve custom naming and descriptions for your snapshots using a combination of AWS services. However, it's important to note that the CreateSnapshot event from DLM does not trigger EventBridge rules directly, which explains why your attempts with CloudTrail and CloudWatch events were unsuccessful.
Instead, you can implement a solution using AWS Lambda and CloudWatch Events to rename the snapshots after they are created by DLM. Here's how you can approach this:
-
Set up a CloudWatch Event rule to trigger when a snapshot is created by DLM.
-
Create an AWS Lambda function that will be triggered by this CloudWatch Event. This function will be responsible for renaming the snapshot and adding a custom description.
-
In your Lambda function, use the AWS SDK to modify the snapshot tags and description based on your desired naming convention.
Here's a basic outline of what your Lambda function might look like:
import boto3 def lambda_handler(event, context): ec2 = boto3.client('ec2') snapshot_id = event['detail']['snapshot_id'] instance_id = event['detail']['instance_id'] timestamp = event['time'] # Define your custom name and description custom_name = f"snapshot-{instance_id}-{timestamp}" custom_description = f"Custom snapshot for {instance_id} created at {timestamp}" # Add the custom name as a tag and update the description ec2.create_tags( Resources=[snapshot_id], Tags=[ {'Key': 'Name', 'Value': custom_name} ] ) ec2.modify_snapshot_attribute( SnapshotId=snapshot_id, Attribute='description', Value=custom_description ) return { 'statusCode': 200, 'body': f"Snapshot {snapshot_id} renamed to {custom_name} and description updated" }
To verify if your snapshots are being created successfully by DLM, you can check for specific tags on the snapshots. DLM-created snapshots will have a tag with the key 'aws:dlm:lifecycle-policy-id'. Additionally, for application-consistent snapshots, you might see tags like 'AppConsistent:true' or system tags indicating the success or failure of pre and post scripts.
If you're experiencing issues with snapshot creation, you might want to implement an automatic recovery mechanism for failed EBS snapshots. This involves setting up an EventBridge rule to send EBS snapshot failure events to an SQS queue, which then triggers a Lambda function to attempt another snapshot creation.
Remember to monitor your DLM metrics in CloudWatch to stay informed about any EBS snapshot failures, as these can occur due to transient issues or service limits.
Sources
Amazon DLM for snapshot automation | AWS re:Post
Automating application-consistent Amazon EBS Snapshots for Windows applications | AWS Storage Blog
Automatic Recovery for Failed EBS Snapshot | AWS re:Post
Relevant content
- asked a year ago
- asked 7 months ago
- asked 2 years ago
- AWS OFFICIALUpdated 9 months ago

The above AI response doesn't work.