0

I am unable to get TaskDefinitionArn in a variable .

I am trying to do the below:

cloudwatchTriggerForLambdaFunction:
Type: 'AWS::Events::Rule'
Properties:
  Description: 'Trigger Lambda function according to the specified schedule'
  ScheduleExpression: !Ref CronExpression
  State: ENABLED
  Targets:
    - Arn: !Sub '${LambdaFunction.Arn}'
      Id: cloudwatchTriggerForLambdaFunction
    - Arn: !GetAtt FargateLauncher.Arn
      Id: fargate-launcher
      Input: 
        !Sub |
          {
               taskDefinition: "${TaskDefinitionArn}"
           }

but the above throwing the error like below:

 An error occurred (ValidationError) when calling the CreateStack operation: Template error: instance of Fn::Sub references invalid resource attribute TaskDefinitionArn.

I cannot get the value of TaskDefinitionArn in a parameter as this is going to be created runtime so must get this lie above. Pleae suggest some solution to this. Thanks in advance.

3 Answers3

1

I had to change my approach a bit.

I am now using direct cloudwatch trigger on fargate task instead of running lambda function to trigger fargate task.

So that way, this query seems invalid.

If you try this way do try to create the arnanually like

**arn:aws:ecs:${AWS::AccountId}:${AWS:Region}**
Alex Stephens
  • 3,017
  • 1
  • 36
  • 41
0

Since your resource name is TaskDefinition, you should reference it by name.

{
    taskDefinition: "${TaskDefinition}"
}

But according to this aws documentation, the ecs event rule should be defined as below

{
  "Group" : String,
  "LaunchType" : String,
  "NetworkConfiguration" : NetworkConfiguration,
  "PlatformVersion" : String,
  "TaskCount" : Integer,
  "TaskDefinitionArn" : String
}

therefore the key should be TaskDefinitionArn not taskDefinition. Please have a look at the reference.

Arun Kamalanathan
  • 8,107
  • 4
  • 23
  • 39
  • i understand that you want to create the task definition and reference it in the rule. thats exactly what happens when you reference the task definition resource as i showed above. when you reference a task reference as `${TaskDefinition}` it will return the `Arn` of the task definition. – Arun Kamalanathan Apr 05 '20 at 07:53
  • I would like to add @chadawagner here - please do help me . TIA – Vishal Bobade Apr 05 '20 at 07:55
  • - this ${TaskDefinition} will return the value of parameter TaskDefinition if its existed. Instead if we need Arn of Task definition it should be !Ref TaskDefinition. in my case. But my question is how can I get the value of TaskDefinition Arn which i can use in the below input attribute. `Input: !Sub | { "taskDefinition": "${TaskDefinitionArn}" }` – Vishal Bobade Apr 05 '20 at 08:04
  • I understand that you want to pass the Arn of your task definition in the Input attribute. It should work if you simply substitute as I said before. Because you can reference the parameter and the resources the same way. And in the case of TaskDefinition when you reference it just by name, it will return the Arn. Can you try my suggestion by referring the task by `"${TaskDefinition}"`. Could you please try it for me and post the results. Thanks – Arun Kamalanathan Apr 05 '20 at 08:38
  • How did you go ? – Arun Kamalanathan Apr 06 '20 at 08:17
0

I agree - but i am using this approach link below to run fargate task with cloudwatch trigger where he is using TaskDefinitionArn as a parameter. Which I don;t want to do. I want to get the value of Arn itself while running my task.

Let me know if you did not get my query.

creating a 'Target' for a cloudwatch event rule via cloudformation for a fargate launchtype task