Creating Amazon ECS Scheduled Tasks for MI utilities

Amazon ECS supports the ability to schedule tasks on either a cron-like schedule or in a response to CloudWatch Events. This is supported for Amazon ECS tasks using both the Fargate and EC2 launch types.

If you have tasks to run on a schedule in your cluster, such as a backup operation or a log scan, you can use the Amazon ECS console to create a CloudWatch Events rule. Your scheduled event rule can be set to either a specific interval (run every N minutes, hours, or days), or for more complicated scheduling, you can use a cron expression.

Metric Insights application has its own utilities to create backups of your database and all critical data of your application server (mi-app-backup tool), as well as synchronize users with the LDAP server (ldap-user-sync tool). For more information, please refer to:

Backup Your Metric Insights Instance

Syncing Groups and Users from LDAP/AD using 'mi-ldap-usersync' script

If it is not possible to set these 2 tools on the  MI cron job, we strongly recommend to configure  ECS Scheduled Tasks to run these utilities. Follow the below steps to set AWS ECS Scheduled Tasks.

Create scheduled task in cluster

  1. Open Amazon ECS console
  2. Select the cluster you want to create a scheduled task in
  3. On the cluster page click on Scheduled Tasks Tab
  4. Click Create button

Configure scheduled task

Specify the following:

  1. Schedule rule name identify your task in scheduled tasks list
  2. Schedule rule type choose whether to use a fixed interval schedule or a cron expression for your scheduled rule
  3. Run at fixed interval indicate the interval your task should run at, or set cron expression if it was selected in the previous step. For more information, see Schedule Expressions for Rules in the Amazon CloudWatch Events User Guide.

Specify scheduled targets

  1. Target id specify unique identifier for your target
  2. Select Launch type - ECS2
  3. Task Definition Family - choose the name of your web slave container from the list

Configure CloudWatch Events IAM role

  1. Leave ecsEventsRole for CloudWatch Events IAM role for this target
  2. expand the web section under Container overrides header
  3. Command override: specify the command that should be executed according to the schedule

Command Examples:

 mi-app-backup /some/dir - saving tarball in a predefined folder (by default tarball created under /opt/mi/backup)

mi-app-backup -k2  - keep only last two backups

mi-ldap-usersync provision "CN=some_group,OU=groups,OU=business_org,DC=global,DC=myorg,DC=com" --ldap-host="ldaps://"  --ldap-user="cn=miadmin,cn=users,dc=global,dc=myorg,dc=com" --ldap-pass="password" --verbose -  basic provision command for syncing LDAP/AD groups and users in Metric Insights.

To run a custom script, please save the script in the directory /opt/mi/custom/scripts and indicate the full path to script in Command override field. For example: ./opt/mi/custom/scripts/

4.    After specifying the command, click Create.

Command line can contain optional parameters for running command. For more information on the options available, please refer to:

Backup Your Metric Insights Instance

Syncing Groups and Users from LDAP/AD using 'mi-ldap-usersync' script