Fork me on GitHub
#aws
<
2022-07-19
>
Drew Verlee04:07:16

My toy cf template fails. I shall resolve to understand why in the morning. The error is Requested attribute Arn does not exist in schema for AWS::ECS::TaskDefinition and i don't understand why because i feel like it should have an Arn. My worry is that you have to have a cluster that the task definition is part of. Though that doesn't make sense to me because i thought the point of fargate was that you didn't have to do that.

AWSTemplateFormatVersion: 2010-09-09
Description: The template used to create an ECS Task definition from the ECS Console.
Resources:
  JarCreator:
    Type: 'AWS::ECS::TaskDefinition'
    Properties:
      ContainerDefinitions:
        - LogConfiguration:
            Options:
              awslogs-group: /ecs/tiny-function-task
              awslogs-region: us-east-2
              awslogs-stream-prefix: ecs
              awslogs-create-group: 'true'
            LogDriver: awslogs
          Name: tiny-function
          Image: ''
          Essential: true
          PortMappings: []
          EnvironmentFiles: []
      Family: tiny-function-task
      NetworkMode: awsvpc
      RequiresCompatibilities:
        - FARGATE
      Cpu: .5 vCPU
      Memory: 1 GB
      RuntimePlatform:
        CpuArchitecture: X86_64
        OperatingSystemFamily: LINUX
      ExecutionRoleArn: 'arn:aws:iam::595680822218:role/ecsTaskExecutionRole'
      Tags:
        - Key: 'ecs:taskDefinition:createdFrom'
          Value: ecs-console-v2
        - Key: 'ecs:taskDefinition:stackId'
          Value: !Ref 'AWS::StackId'
    Metadata:
      'AWS::CloudFormation::Designer':
        id: 3b65a475-eeb6-45ea-b1f5-314e0b332333
  Hourly:
    Type: 'AWS::Events::Rule'
    Properties:
      Description: it does things you cant imagine
      ScheduleExpression: rate(1 hour)
      State: Enabled
      Targets: 
        - Arn: !GetAtt
          - JarCreator
          - Arn
          ID: "Id123"
          EcsParameters:
            TaskDefinationArn: !Ref JarCreator
            EnableExecuteCommand: True
            LaunchType: FARGATE
Outputs:
  TaskDefinitionARN:
    Description: The created task definition ARN.
    Value: !Ref JarCreator

hiredman04:07:03

It has been a few years since I tangled with cloudformation, but if recall you can think of a resource definition as sort of an expression that evaluates to creating the resource

hiredman04:07:09

The result of creating the resource is some value, which is bound to the name of the resource !Ref gets you the value bound to the name

hiredman04:07:35

The value returned from creating the resource is not always the arn is the tricky thing

hiredman04:07:45

Which I think is what that error means

valtteri04:07:53

You're trying to reference attribute abc.Arn but you get the arn with just referencing abc

jjttjj13:07:10

@drewverlee Yeah in this case it looks like TaskDefinition does return the Arn with Ref, but Arn isn't availble with GetAtt, and you attempt to get it with GettAtt in the hourly rule. https://theburningmonk.com/cloudformation-ref-and-getatt-cheatsheet/ This list I linked before will show what is returned/available with GetAtt all in one place

Drew Verlee14:07:06

Thanks everyone. I think the more fundamental issue is that i was trying to target the task definition resource directly instead of the <AWS::ECS::Service|AWS::ECS::Servic>e that runs the task. I thought with fargate you didn't need to even reference this layer, but that doesn't seem to be the case.