- Create EC2
- I left VPC, Subnet, Security Group information in here. Please set up with yours.
- To use the scheduler CLI, you must have credentials for the AWS CLI.
Your credentials must have the following permissions:
lambda:InvokeFunction – To invoke the InstanceSchedulerMain function in the scheduler stack, and to update the schedule and period information in the scheduler configuration database from the command line
cloudformation:DescribeStackResource – To retrieve the physical resource ID of the AWS Lambda function from the stack to handle the CLI request
The CLI in this solution requires
Python 3.8+Go To
IAMfrom AWS Console
- Click
Roles
- Click
Create role
- Select
EC2and ClickNext
- Choose
AWSLambdaInvocation-DynamoDB
- Choose
AWSCloudFormationReadOnlyAccess
- Write
EC2-Instance-Scheduler-Role
- Click
Create role
- Attach IAM role to EC2
- Select
EC2-Instance-Scheduler-Roleand ClickUpdate IAM role
- Select EC2 and Click
Connect
- Click
Connect
- Type
python3 --version and click enter
- Type
sudo yum install python3.x86_64 python3-pip.noarch - Type
python3 --version - Type
wget https://s3.amazonaws.com/solutions-reference/instance-scheduler-on-aws/latest/instance_scheduler_cli-1.5.3-py3-none-any.whl - Type
pip install instance_scheduler_cli-1.5.3-py3-none-any.whl - Type
scheduler-cli --version - Type
scheduler-cli -h Download the CloudFormation for InstanceScheduler , Click Here
or you can directly go by Click Here
.This will go to CloudFormation Page directly.Go to
CloudFormation
- Click
With new resources (standard)
- Click
Choose file
- Click
Next
Enter InstanceScheduler as a stack name
Scroll down and click on next
Scroll down and click on next
Scroll down and click on submit
- Wait the CloudFormation stack is deployed successfully.
- Type
scheduler-cli describe-schedules --region ap-southeast-1 --stack InstanceScheduler - You will see the out like this but timezone is different with our local time
{ "Schedules": [ { "Description": "Instances running", "Name": "running", "UseMetrics": false, "Type": "schedule", "OverrideStatus": "running" }, { "Timezone": "UTC", "Description": "Vertical scaling on weekdays, based on UTC time", "Periods": [ "working-days@t2.micro", "weekends@t2.nano" ], "Name": "scale-up-down", "Type": "schedule" }, { "Timezone": "US/Pacific", "Description": "Office hours in Seattle (Pacific)", "Periods": [ "office-hours" ], "Name": "seattle-office-hours", "Type": "schedule" }, { "Description": "Instances stopped", "Name": "stopped", "UseMetrics": false, "Type": "schedule", "OverrideStatus": "stopped" }, { "Timezone": "Europe/London", "Description": "Office hours in UK", "Periods": [ "office-hours" ], "Name": "uk-office-hours", "Type": "schedule" } ] } - Type
scheduler-cli describe-periods --region ap-southeast-1 --stack InstanceScheduler - You will see the out like this but timezone is different with our local time
{ "Periods": [ { "Months": [ "jan/3" ], "Description": "Every first monday of each quarter", "Weekdays": [ "mon#1" ], "Name": "first-monday-in-quarter", "Type": "period" }, { "Begintime": "09:00", "Description": "Office hours", "Endtime": "17:00", "Weekdays": [ "mon-fri" ], "Name": "office-hours", "Type": "period" }, { "Description": "Days in weekend", "Weekdays": [ "sat-sun" ], "Name": "weekends", "Type": "period" }, { "Description": "Working days", "Weekdays": [ "mon-fri" ], "Name": "working-days", "Type": "period" } ] } We have to change information at
DynamoDBso go toDynamoDBfrom AWS ConsoleClick
Explore Items
- Select
InstanceScheduler-ConfigTable-EIC9ZOW4EYKIandEdit Item
- Change
nameandtimezonelike this and clickRecreate Item
- Type
scheduler-cli describe-schedules --region ap-southeast-1 --stack InstanceScheduler - You will see the out like this and timezone is changed with our local time
{ "Schedules": [ { "Timezone": "Asia/Yangon", "Description": "Office hours in Seattle (Pacific)", "Periods": [ "office-hours" ], "Name": "myanmar-office-hours", "Type": "schedule" }, { "Description": "Instances running", "Name": "running", "UseMetrics": false, "Type": "schedule", "OverrideStatus": "running" }, { "Timezone": "UTC", "Description": "Vertical scaling on weekdays, based on UTC time", "Periods": [ "working-days@t2.micro", "weekends@t2.nano" ], "Name": "scale-up-down", "Type": "schedule" }, { "Description": "Instances stopped", "Name": "stopped", "UseMetrics": false, "Type": "schedule", "OverrideStatus": "stopped" }, { "Timezone": "Europe/London", "Description": "Office hours in UK", "Periods": [ "office-hours" ], "Name": "uk-office-hours", "Type": "schedule" } ] } - Type
scheduler-cli describe-periods --region ap-southeast-1 --stack InstanceScheduler - You will see the out like this and timezone is changed with our local time
{ "Periods": [ { "Months": [ "jan/3" ], "Description": "Every first monday of each quarter", "Weekdays": [ "mon#1" ], "Name": "first-monday-in-quarter", "Type": "period" }, { "Begintime": "09:00", "Description": "Office hours", "Endtime": "17:00", "Weekdays": [ "mon-fri" ], "Name": "office-hours", "Type": "period" }, { "Description": "Days in weekend", "Weekdays": [ "sat-sun" ], "Name": "weekends", "Type": "period" }, { "Description": "Working days", "Weekdays": [ "mon-fri" ], "Name": "working-days", "Type": "period" } ] } Go to Tag Editor from AWS Console
Regions -
ap-southeast-1Resource types -
All supported resources typesTag key -
EnvironmentOptional tag value -
Dev
- Click
Search resourcesand ClickManage tags of selected resources
Click
AddTag key -
ScheduleOptional tag value -
myanmar-office-hoursClick
Review and apply tag changes
- Click
Apply changes to all selected
Resources & Next Steps
- 📦 Full Code Repository: AWS Learning Labs - Get the complete, working code from this post
- 📖 More Deep Dives: Whispering Cloud Insights - Read other technical articles
- 💬 Join Discussion: DEV Community - Share your thoughts and questions
- 💼 Let's Connect: Linkedin - I'd love to connect with you










































Top comments (0)