cloudformation-coverage-roadmap icon indicating copy to clipboard operation
cloudformation-coverage-roadmap copied to clipboard

[AWS::ECS::TaskDefinition] - [Coverage] - Add support for restartPolicy property in ContainerDefinition

Open ashishdhingra opened this issue 1 year ago • 1 comments

Name of the resource

AWS::ECS::TaskDefinition

Resource name

No response

Description

Customer reported an issue https://github.com/aws/aws-cdk/issues/31127 on CDK GitHub repository requesting to add support for container definition's restart policy.

The CloudFormationSchema::aws-ecs-taskdefinition.json and AWS::ECS::TaskDefinition ContainerDefinition doesn't appear to specify support for Restart policy. So looks like CloudFormation is yet to add support for restartPolicy.

Please advise when the support for restartPolicy would be added to AWS::ECS::TaskDefinition ContainerDefinition.

Other Details

No response

ashishdhingra avatar Aug 16 '24 18:08 ashishdhingra

Fairly important for us, would love to test this feature.

r-heimann avatar Aug 20 '24 05:08 r-heimann

RestartPolicy is now available in Cloudformation, I have verified it is available in the resource provider schemas available here: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resource-type-schemas.html

sparrc avatar Aug 30 '24 20:08 sparrc

I tested it just now, and while the docs show RestartPolicy as a possible element, trying to update TaskDefinition with a new

      RestartPolicy:
        Enabled: true
        RestartAttemptPeriod: 300

property resulted in Resource handler returned message: "Model validation failed (#: extraneous key [RestartPolicy] is not permitted)" (RequestToken: 0352b40a-fb1f-ecd0-4121-d5162d41ab4f, HandlerErrorCode: InvalidRequest).

Complete TaskDefinition:


  TaskDefinition:
    Type: "AWS::ECS::TaskDefinition"
    Properties:
      Family: !Sub "${EnvironmentName}-${ServiceName}-td"
      ContainerDefinitions:
        - Essential: true
          Name: !Sub "${EnvironmentName}-${ServiceName}-container"
          Image: !Sub "${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/${ContainerImageRepository}:${ContainerImageTag}"
          Environment:
            - Name: "spring_profiles_active"
              Value: !Ref EnvironmentName
          PortMappings:
            - ContainerPort: 8080
              Protocol: "tcp"
          LogConfiguration:
            LogDriver: "awslogs"
            Options:
              awslogs-group: !Ref LogGroup
              awslogs-region: !Ref AWS::Region
              awslogs-stream-prefix: "ecs"
      ExecutionRoleArn: !Sub "arn:aws:iam::${AWS::AccountId}:role/ecsTaskExecutionRole"
      NetworkMode: "awsvpc"
      RequiresCompatibilities:
        - "FARGATE"
      Cpu: !Ref ResourcesCpu
      Memory: !Ref ResourcesMemory
      RestartPolicy:
        Enabled: true
        RestartAttemptPeriod: 300

Update: as pointed out below, RestartPolicy should be part of ContainerDefinition, not TaskDefinition. That fixed my issue.

grimsa-aurorasolar avatar Sep 03 '24 06:09 grimsa-aurorasolar

@grimsa-aurorasolar RestartPolicy goes on the ContainerDefinition, not the TaskDefinition. See https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ecs-taskdefinition-containerdefinition.html#cfn-ecs-taskdefinition-containerdefinition-restartpolicy

poost-frey avatar Sep 03 '24 14:09 poost-frey

The CFN spec aws-ecs-taskdefinition.json is not yet updated with the specification where RestartPolicy property has been supported in ContainerDefinition. As soon as the change is available there, CDK L1 constructs should be updated shortly thereafter.

ashishdhingra avatar Sep 03 '24 18:09 ashishdhingra

RestartPolicy is now available in ContainerDefinition. Closing this Github issue out.

alanrdze avatar Oct 28 '24 21:10 alanrdze