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:
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.
- Open Amazon ECS console https://console.aws.amazon.com/ecs/
- Select the cluster you want to create a scheduled task in
- On the cluster page click on Scheduled Tasks Tab
- Click Create button
Specify the following:
- Schedule rule name identify your task in scheduled tasks list
- Schedule rule type choose whether to use a fixed interval schedule or a cron expression for your scheduled rule
- 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.
- Target id specify unique identifier for your target
- Select Launch type - ECS2
- Task Definition Family - choose the name of your web slave container from the list
- Leave ecsEventsRole for CloudWatch Events IAM role for this target
- expand the web section under Container overrides header
- Command override: specify the command that should be executed according to the schedule
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.internal.myorg.com" --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/MIAppBackup.sh
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: