Automated deployment - AWS Instance Scheduler

Automated deployment

Before you launch the automated deployment, please review the architecture, configuration, and other considerations discussed in this guide. Follow the step-by-step instructions in this section to configure and deploy Instance Scheduler into your account.

Time to deploy: Approximately five (5) minutes

Update the stack

If you have previously deployed the solution, follow this procedure to update the AWS Instance Scheduler CloudFormation stack to get the latest version of the solution’s framework.

  1. Sign in to the AWS CloudFormation console, select your existing aws-instance-scheduler CloudFormation stack, and select Update.

  2. Select Replace current template.

  3. Under Specify template:

  4. Select Amazon S3 URL.

  5. Copy the link of the latest template.

  6. Paste the link in the Amazon S3 URL box.

  7. Verify that the correct template URL shows in the Amazon S3 URL text box, and choose Next. Choose Next again.

  8. Under Parameters, review the parameters for the template and modify them as necessary. Refer to Step 1. Launch the Stack for details about the parameters.

  9. Choose Next.

  10. On the Configure stack options page, choose Next.

  11. On the Review page, review and confirm the settings. Be sure to check the box acknowledging that the template might create AWS Identity and Access Management (IAM) resources.

  12. Choose View change set and verify the changes.

  13. Choose Update stack to deploy the stack.

    You can view the status of the stack in the AWS CloudFormation console in the Status column. You should see a status of UPDATE_COMPLETE in approximately 15 minutes.

Deployment overview

The procedure for deploying this architecture on AWS consists of the following steps. For detailed instructions, follow the links for each step.

Step 1. Launch the instance scheduler stack

  • Launch the AWS CloudFormation template into your AWS account

  • Enter values for the required parameter: Stack Name

  • Review the other template parameters, and adjust if necessary

Step 2. Configure periods

  • Create a period and set the applicable fields for the period

Step 3. Configure schedules

  • Create a schedule and set the applicable fields for the schedule

Step 4. Tag your instances

  • Apply the custom tag to applicable resources

Step 5. Launch the remote stack in secondary accounts (Optional)

  • Launch the AWS CloudFormation template into your AWS account

  • Enter values for the required parameter: Primary account

Step 1. Launch the instance scheduler stack

This automated AWS CloudFormation template deploys the Instance Scheduler in AWS Lambda, and configures related components. Please make sure that you’ve verified the settings for your instances before launching the stack.

Note

You are responsible for the cost of the AWS services used while running this solution. For more details, visit to the Cost section in this guide, and refer to the pricing webpage for each AWS service used in this solution.

  1. Sign in to the AWS Management Console and click the button below to launch the aws-instance-scheduler AWS CloudFormation template.

    
                                Instance Scheduler launch button

    You can also download the template as a starting point for your own implementation.

  2. The template is launched in the US East (N. Virginia) Region by default. To launch the Instance Scheduler in a different AWS Region, use the region selector in the console navigation bar.

  3. On the Select Template page, verify that you selected the correct template and choose Next.

  4. On the Specify Details page, assign a name to your solution stack.

    Note

    The stack name cannot contain more than 36 characters.

  5. Under Parameters, review the parameters for the template, and modify them as necessary.

    This solution uses the following default values.

    Parameter Default Description
    Instance Scheduler tag name Schedule

    This tag identifies instances to receive automated actions, and also allows for custom start-stop parameters.

    If you choose to modify the default value, make sure to assign a name that will be easy to apply consistently and correctly across all necessary instances.

    Service(s) to schedule EC2 The services to schedule. Select EC2, RDS, or Both.
    Schedule Aurora Clusters No Choose whether to schedule Amazon Aurora clusters. To turn on Aurora cluster scheduling, you must select RDS or Both for the Service(s) to schedule parameter.
    Create RDS instance snapshot Yes

    Choose whether to create a snapshot before stopping RDS instances

    Note

    Snapshots are not available for Amazon Aurora clusters.

    Scheduling enabled Yes Select No to temporarily turn off scheduling.
    Region(s) <Optional input>

    List of Regions where instances will be scheduled. For example, us-east-1, us-west-1.

    Note

    If you leave this parameter blank, the solution will use the current Region.

    Default time zone UTC Default time zone for schedules. For a list of acceptable time zone values, refer to the TZ column of the List of TZ Database Time Zones.
    Cross-account roles <Optional input>

    Comma-delimited list of cross-account roles. For example, arn:aws:iam::111122223333:role/<stackname>SchedulerCrossAccountRole. If you store your cross-account ARNs in the AWS Systems Manager Parameter Store, use the format {param:name}. For more information, refer to AWS Systems Manager Parameter Store.

    Note

    Enter the secondary account CrossAccountRoleArn value(s) in this parameter.

    This account Yes

    Select Yes to allow the task to select resources in this account.

    Note

    If you set this parameter to No, you must configure cross-account roles.

    Frequency 5 The frequency in minutes at which the AWS Lambda function runs. Select 1, 2, 5, 10, 15, 30, or 60.
    Enable CloudWatch Metrics No Choose whether to collect data using CloudWatch Metrics for all schedules. You can override this default setting for an individual schedule when you configure it (refer to Step 3).
    Important

    Enabling this feature will incur charges of $0.90/month per schedule or scheduled service.

    Memory Size 128 The memory size of the solution’s main AWS Lambda function. Increase the default size to schedule a large number of Amazon EC2 and Amazon RDS instances.
    Enable CloudWatch Logs No Choose whether to log detailed information in CloudWatch Logs.
    Enable SSM maintenance windows No Allow the solution to load SSM maintenance windows, so that they can be used for Amazon EC2 instance scheduling.
    Log retention days 30 The log retention period in days
    Started tags <Optional input> Tags to add to started instances. Use a list of tagname=tagvalue pairs.
    Stopped tags <Optional input> Tags to add to stopped instances. Use a list of tagname=tagvalue pairs.
    Send anonymous usage data Yes Send anonymous data to AWS to help us understand solution usage and related cost savings across our customer base as a whole. To opt out of this feature, select No. For more information, refer to the Collection of operational metrics.
  6. Choose Next.

  7. On the Options page, choose Next.

  8. On the Review page, review and confirm the settings. Check the box acknowledging that the template will create AWS Identity and Access Management (IAM) resources.

  9. Choose Create to deploy the stack.

    You can view the status of the stack in the AWS CloudFormation console in the Status column. You should see a status of CREATE_COMPLETE in roughly five (5) minutes.

Step 2. Configure periods

When you deploy the AWS CloudFormation template, the solution creates an Amazon DynamoDB table that contains sample period rules and schedules that you can use as a reference to create your own custom period rules and schedules.

To create a period rule, you can use the Amazon DynamoDB console, the scheduler CLI, or the AWS CloudFormation custom resource that you can create. For details about this stack resource type, refer to Custom resource.

Note

If you use the custom resource to create a period, you must not use the DynamoDB console or scheduler CLI to delete or modify that period. 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.

To create a period rule in DynamoDB, modify one of the periods in the configuration table (ConfigTable). To create a period in the scheduler CLI, use the applicable commands. To create a period using the custom resource, add the applicable fields to the solution’s custom resource.

For an example period configuration, refer to Sample schedule.

Step 3. Configure schedules

To create a schedule, you can use the Amazon DynamoDB console, the scheduler CLI, or the AWS CloudFormation custom resource that you can create. For details about this stack resource type, refer to Custom resource.

Note

If you use the custom resource to create a schedule, you must not use the DynamoDB console or scheduler CLI to delete or modify that schedule. If you do, you will create a conflict between the stored parameters in the stack and the values in the table.

To create a schedule in DynamoDB, modify one of the schedules in the configuration table (ConfigTable). To create a schedule in the scheduler CLI, use the applicable commands. To create a schedule using the custom resource, add the applicable fields to the solution’s custom resource.

For an example schedule configuration, refer to Sample schedule.

Step 4. Tag your instances

When you deployed the AWS CloudFormation template, you defined the name (tag key) for the solution’s custom tag. For the Instance Scheduler to recognize an Amazon EC2 or Amazon RDS instance, the tag key on that instance must match the custom tag name stored in the Amazon DynamoDB table. Therefore, it is important that you apply tags consistently and correctly to all applicable instances. You can continue to use existing tagging strategies for your instances while using this solution. For more information, refer to Tagging Your Amazon EC2 Resources and Tagging Your Amazon RDS Resources.

On the AWS Management Console, use the Tag Editor to apply or modify tags for multiple resources at a time. You can also apply and modify tags manually in the console.

Setting the tag value

When you apply a tag to a resource, use the tag key you defined during initial configuration. Set the tag key to Schedule and set the tag value to the same scheduler name in the Amazon DynamoDB table to schedule your resource. You can also update the scheduler name in the Amazon DynamoDB table.

Note

For Amazon RDS instances, the tag value can be from 1 to 256 Unicode characters in length and cannot be prefixed with "aws:". The string can contain only the set of Unicode letters, digits, white-space, '_', '.', '/', '=', '+', '-' (Java regex: "^([\\p{L}\\p{Z}\\p{N}_.:/=+\\-]*)$"). For more information, refer to Tagging Your Amazon RDS Resources.

Step 5. Launch the remote stack in secondary accounts (Optional)

This automated AWS CloudFormation template configures secondary account permissions.

  1. Navigate to the AWS Instance Scheduler stack Outputs tab and copy the Value of SchedulerRole.

  2. Sign in to the AWS Management Console of the applicable secondary account and click the button to below to launch the aws-instance-scheduler-remote AWS CloudFormation template.

    
                                Instance Scheduler remote template launch button

    You can also download the template as a starting point for your own implementation.

  3. The template is launched in the US East (N. Virginia) Region by default. To launch the Instance Scheduler in a different AWS Region, use the region selector in the console navigation bar.

  4. On the Select Template page, verify that you selected the correct template and choose Next.

  5. On the Specify Details page, assign a name to your remote stack.

  6. Under Parameters, review the parameter for the template, and modify it.

    Parameter Default Description
    Primary account <Requires Input>

    Enter the account number of the account with the primary Instance Scheduler stack. This parameter gives the solution permission to schedule Amazon EC2 and Amazon RDS instances in this account.

  7. Choose Next.

  8. On the Options page, choose Next.

  9. On the Review page, review and confirm the settings. Be sure to check the box acknowledging that the template will create AWS Identity and Access Management (IAM) resources.

  10. Choose Create to deploy the stack.

    You can view the status of the stack in the AWS CloudFormation console in the Status column. You should see a status of CREATE_COMPLETE in approximately five minutes.