16

I have created a Task Definition on Elastic Container Service and have successfully run it in a Fargate cluster. However when I create a Scheduled Task in said cluster the option for "Launch Type" is hardcoded to EC2. Is there a way, perhaps through the command line to schedule the task to run on Fargate?

enter image description here

Jared S
  • 380
  • 4
  • 14

7 Answers7

10

Heads up ! This is now supported in AWS:

https://aws.amazon.com/about-aws/whats-new/2018/08/aws-fargate-now-supports-time-and-event-based-task-scheduling/

Although not in some regions - As at Apr-19 it still wasn't supported in EU-west-2 (London). Check the table at the top of this page to see if it's supported in the region you want: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/scheduled_tasks.html

Tom Greenwood
  • 1,502
  • 14
  • 17
David Lin
  • 13,168
  • 5
  • 46
  • 46
  • 2
    Seems to not be cloudformationable yet; Not in the docs // getting errors for AWS::Events::Rule not supporting NetworkConfiguration, which the UI states ought be required for tasks with awsvpc network configuration (fargate tasks). – kian Sep 18 '18 at 23:13
  • 2
    That's right, Cloudformation is not FULLY supported yet. You can create the scheduled tasks using cloudformation template. But manual task configuration is required in AWS console. – David Lin Sep 19 '18 at 03:44
8

There seem to be no way of scheduling a task on FARGATE.

Only way it can be done right now seems to be by having your 'scheduler' external to ECS. I did it with a lambda. You can also use something like a jenkins or a simple cron task that fires the aws-cli command to ECS, in both these cases though you will need an instance always running.

I wrote a lambda that accepts the params (overrides) to be sent to the ECS task and has the schedule the task was supposed to have.

Update: It seems there is a schedule tab in FARGATE Cluster details now that will allow you set cron schedules on ECS tasks.

NikhilWanpal
  • 2,960
  • 3
  • 23
  • 40
5

While the AWS Documentation gives you ways to do this through CloudFormation, it seems like they've not yet released this feature anyway. I have been trying to do something similar and ran into the same issue. Once it does become available, this link from the aws docs should be useful. Here's how they suggest doing it, but I keep running into errors saying NetworkConfiguration is not recognized and LaunchType is not recognized.

 "EcsParameters": { 
        "Group": "string",
        "LaunchType": "string",
        "NetworkConfiguration": { 
           "awsvpcConfiguration": { 
              "AssignPublicIp": "string",
              "SecurityGroups": [ "string" ],
              "Subnets": [ "string" ]
           }
        },

Update: Here is an alternative that did end up working for me through the aws events put-targets command on the aws cli!

Make sure your aws cli is up to date. This method fails for older versions of the cli. run this to update: pip install awscli --upgrade --user

After that, you should be good to go. Use the aws events put-targets --rule <value> --targets <value> command. Make sure that before you run this command you have a rule already defined on your cluster. If not, you can do that with the aws events put-rule cmd too. Refer to the AWS docs for put-rule, and for put-targets.

An example of a rule from the documentation is given below:

aws events put-rule --name "DailyLambdaFunction" --schedule-expression "cron(0 9 * * ? *)"

The put-targets command that worked for me is this:

aws events put-targets --rule cli-RS-rule --targets '{"Arn": "arn:aws:ecs:1234/cluster/clustername","EcsParameters": {"LaunchType": "FARGATE","NetworkConfiguration": {"awsvpcConfiguration": {"AssignPublicIp": "ENABLED", "SecurityGroups": [ "sg-id1233" ], "Subnets": [ "subnet-1234" ] }},"TaskCount": 1,"TaskDefinitionArn": "arn:aws:ecs:1234:task-definition/taskdef"},"Id": "sampleID111","RoleArn": "arn:aws:iam:1234:role/eventrole"}'
tanvi
  • 568
  • 2
  • 11
  • 32
2

You can create a CloudWatch rule that uses a schedule as the event source and an ESC task as the target.

André
  • 2,042
  • 1
  • 23
  • 26
0

No this is not supported yet unfortunately. There is an open issue here. Hopefully it gets done soon as I would like to use it as well!

coolboyjules
  • 2,300
  • 4
  • 22
  • 42
  • The bug linked is about allowing ECS scheduling from command line and does not mention anything related to FARGATE. The cli does not have a way of scheduling is different from there is no way to schedule a task on FARGATE. – NikhilWanpal Jan 18 '18 at 05:19
0

Disclosure: I work for SenseDeep that provides Powerdown @ https://www.powerdown.io

Other services provide this functionality. PowerDown gives the ability to schedule Fargate services. This is at the service level, not the task level, but it is easy to create services for tasks. For example: you could schedule a CICD pipeline container to run 9-5 M-F.

SenseDeep
  • 3,026
  • 3
  • 17
  • 19
0

It's not possible to have EC2 instances and Fargate instances at the same cluster.

It's possible to schedule a Fargate instance. Create a specific service and update that from aws tools. Ex:

aws ecs update-service --service my-http-service --task-definition

https://docs.aws.amazon.com/cli/latest/reference/ecs/update-service.html

Useful resources:

You could use the ECS aws tools and execute on lambda or travis.

Check out this medium post:

https://medium.com/@joseignaciocastelli92/how-to-create-a-continuous-deployment-process-using-ecs-fargate-docker-travis-410d84b4d99e

At the button has this repository that has the aws commands:

https://github.com/JicLotus/ecs-farate-scripts-to-deploy-and-build

Bests