Reputation: 1343
I have created cfn template to trigger cloudwatch event periodically to run an ecs task with Fargate launch type. The CW rule looks like below:
sfECSScheduleEventRule:
Type: AWS::Events::Rule
Description: ''
Properties:
State: ENABLED
ScheduleExpression: rate(1 minute)
Name: !Sub sf-eventrule-ecs-${WPRegion}-${WPEnv}
Targets:
- Id: !Sub sf-ecs-target-task-${WPRegion}-${WPEnv}
Arn: !GetAtt
- ECSCluster
- Arn
RoleArn: !GetAtt
- ECSTaskExecutionRole
- Arn
EcsParameters:
#arn:aws:ecs:ap-northeast-1:448965722616:task-definition/fargate-task-jp-stg:latest
TaskDefinitionArn: !Ref sfECSTaskDefinition
TaskCount: !Ref ECSTaskDesiredCount
LaunchType: FARGATE
PlatformVersion: 'LATEST'
NetworkConfiguration:
AwsVpcConfiguration:
AssignPublicIp: DISABLED
Subnets:
- !Ref sfPrivateSubnet1
When I create the stack, I find the rule's target is like below:
Which fails to trigger the task. But when I change task revision from 4 to Latest manually, then it works. Task executes periodically.
How I can change the rule So that it points to the latest?
Upvotes: 1
Views: 5064
Reputation: 238169
You are using:
TaskDefinitionArn: !Ref sfECSTaskDefinition
According to the docs this returns arn with the revision number. Also according to TaskDefinitionArn:
If no task revision is supplied, it defaults to the most recent revision at the time of resource creation.
Thus I think if you manually create the arn, you should be able to get the most recent revision.
!Sub "arn:aws:ecs:${AWS::Region}:${AWS::AccountId}:task-definition/fargate-task-jp-stg"
Don't know if your task family name fargate-task-jp-stg
is parameterized or not in the template. If yes, then you can also reference it in the Sub
intrinsic function.
Upvotes: 2