Auto-snapshot AWS Lightsail every Monday, Wednesday, and Friday

0

I am currently using the AWS Lightsail service and I would like to set up an auto-snapshot,

but I only want it to occur on Mondays, Wednesdays, and Fridays.

In the picture below i can only set daily.

Can someone please assist me with the steps to achieve this?

Any help would be greatly appreciated.

aws

  • Please let me know if I answered your question and select my answer. Thank you

asked a year ago228 views
1 Answer
0

To set up an auto-snapshot in AWS Lightsail on specific days of the week, you'll need to use a combination of AWS CloudWatch Events and AWS Lambda. Here are the steps to achieve this:

Create a new Lambda function: First, create a new Lambda function in the AWS Management Console. You can choose any runtime you like, but we recommend using Python, as it's easy to work with and has good support for AWS SDKs.

Configure the function: Once the function is created, you'll need to configure it to take a snapshot of your Lightsail instance. Here's some sample Python code to get you started:

import boto3

def lambda_handler(event, context): client = boto3.client('lightsail') response = client.create_instance_snapshot( instanceSnapshotName='YourSnapshotName', instanceName='YourInstanceName' )

This code will create a new snapshot of your Lightsail instance with the given name.

Create a CloudWatch event rule: Next, you'll need to create a CloudWatch event rule that triggers your Lambda function on the days you want to take a snapshot. Here's some sample JSON code to get you started:

{ "scheduleExpression": "cron(0 0 ? * MON,WED,FRI *)", "targets": [ { "arn": "arn:aws:lambda:REGION:ACCOUNT_ID:function:FUNCTION_NAME", "id": "MyTarget" } ] }

This code will trigger your Lambda function at 12:00am UTC on Mondays, Wednesdays, and Fridays. Be sure to replace REGION, ACCOUNT_ID, and FUNCTION_NAME with the appropriate values.

Test the setup: Finally, test the setup by waiting for the scheduled time to arrive and checking if a new snapshot has been created. You can also check the CloudWatch Logs for your Lambda function to see if there were any errors. That's it! With these steps, you can set up an auto-snapshot in AWS Lightsail on specific days of the week. Please let me know if that answered your question.

AWS
EXPERT
ZJon
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions