Scheduling start and stop of on-demand notebook instances
-
Create Lambda function for starting and stopping on-demand notebook instances with specific keywords in their name. For this example, our development team’s on-demand notebook instances have names starting with dev-.
-
Your Lambda function should have the SageMakerFullAccess policy attached to its execution IAM role.
-
Under Basic Settings, change Timeout to 15 minutes (max). This step makes sure the function has the maximum allowable timeout range during stopping and starting multiple notebooks.
Now that you have created the functions, you need to create an event to trigger these functions on a specific schedule.
We use cron expression format for the schedule. For more information about creating your custom cron expression, see Schedule Expressions for Rules. All scheduled events use UTC time zone, and the minimum precision for schedules is 1 minute.
For example, the cron expression for 7:00 AM, Monday through Friday throughout the year, is 0 7 ? * MON-FRI *
, and for 9:00 PM on the same days is 0 21 ? * MON-FRI *
.
To create the event for stopping your instances on a specific schedule, complete the following steps:
- On the CloudWatch console, under Events, choose Rules.
- Choose Create rule.
- Under Event Source, select Schedule, and then select Cron expression.
- Enter your cron expression (for example, 21 ? * MON-FRI * for 9:00 PM Monday through Friday).
- Under Targets, choose Lambda function.
- Choose your function from the list
- Choose Configure details
- Add a name for your event, such as
Stop-Notebooks-Event
, and a description. - Leave Enabled 10 Choose Create