AWS Instance Scheduler
AWS Instance Scheduler

Appendix D: Custom Resource

You can use the Instance Scheduler’s AWS CloudFormation custom resource (ServiceInstanceSchedule) to configure schedules and periods. The custom resource uses the same names and syntax as the fields in the configuration Amazon DynamoDB table. For more information on the fields for schedules, see Schedule Definitions. For more information on the fields for periods, see Period Definitions.

When using the custom resource to configure a schedule or period, you must include the account, AWS Region, and name of the deployed schedule stack in the ServiceToken field.

When you use the custom resource to create a schedule, the name of that schedule is the logical resource name of the custom resource by default. To specify a different name, use the Name property of the custom resource. The solution also adds the stack name to the schedule name as a prefix by default. If you do not want to add the stack name as a prefix, use the NoStackPrefix property.

When you use the Name and NoStackPrefix properties, make sure you choose unique schedule names. If a schedule with the same name already exists, the resource will not be created or updated.

The following sample custom resource code shows a schedule (OfficehoursNL) that contains two periods.

AWSTemplateFormatVersion: 2010-09-09 Metadata: 'AWS::CloudFormation::Designer': {} Resources: DutchOfficehours: Type: 'Custom::ServiceInstanceSchedule' Properties: Name: NL-OfficeHours NoStackPrefix: 'True' Description: Office hours in NL ServiceToken: >- arn:aws:lambda:region:accountid:function:name of scheduler stack-InstanceSchedulerMain Enforced: 'True' Timezone: Europe/Amsterdam Periods: - Description: Opening hours on weekdays BeginTime: '08:00' EndTime: '18:00' WeekDays: Mon-Fri - Description: Opening hours in weekend BeginTime: '09:00' EndTime: '17:00' WeekDays: Sat-Sun

Do not use the DynamoDB console or scheduler CLI to delete or modify schedules and periods that were configured using the custom resource. If you do, you will create a conflict between the stored parameters in the stack and the values in the table. Also, do not use periods configured using the custom resource in schedules created using the DynamoDB console or the scheduler CLI.

Before you delete the main Instance Scheduler stack, you must delete all additional stacks that contain schedules and periods created using the custom resource because the custom resource stacks contain dependencies on the main stack’s DynamoDB table.

In the configuration DynamoDB table, schedules and periods that were configured with the custom resource can be identified by the configured_in_stack attribute. The attribute contains the Amazon Resource Name of the stack that was used to create the item.