Open ashishdhingra opened 1 month ago
Fairly important for us, would love to test this feature.
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
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 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
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.
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 toAWS::ECS::TaskDefinition ContainerDefinition
.Other Details
No response