Vishal Bobade
Vishal Bobade

Reputation: 1

writing a cfn template to trigger fargate via cloudwatch events

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.

Upvotes: 0

Views: 261

Answers (3)

VISHAL BOBADE
VISHAL BOBADE

Reputation: 11

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}**

Upvotes: 1

Vishal Bobade
Vishal Bobade

Reputation: 1

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

Upvotes: 0

Arun Kamalanathan
Arun Kamalanathan

Reputation: 8603

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.

Upvotes: 0

Related Questions