aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.65k stars 3.91k forks source link

ecs: support container definition's restart policy #31127

Closed tmokmss closed 1 month ago

tmokmss commented 2 months ago

Describe the feature

Amazon Elastic Container Services (Amazon ECS) now improves container resiliency by giving you the ability to define a flexible container restart policy for restarting individual containers locally, without requiring a full task relaunch. With local container restarts, Amazon ECS can recover your containers from unexpected failures within a few seconds, enhancing your overall task stability by avoiding unnecessary task relaunches.

https://aws.amazon.com/about-aws/whats-new/2024/08/amazon-ecs-restart-containers-task-relaunch/

Use Case

automated container restarts in-place to recover your containers from transient failures such as network disruption or cases where your containers stop unexpectedly

Proposed Solution

Restart policy configuration is added to container definition in task definition. https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html#container_definition_restart_policy

Apparently CFn still does not support it yet though. https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ecs-taskdefinition-containerdefinition.html Maybe they are just updating docs?

Other Information

No response

Acknowledgements

CDK version used

2.152.0

Environment details (OS name and version, etc.)

macOS

ashishdhingra commented 2 months ago

@tmokmss Good morning. Thanks for opening the feature request. I'm unsure if restart policy is a new feature supported by Docker containers. 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.

I will open a ticket with CloudFormation team for their inputs.

Thanks, Ashish

ashishdhingra commented 2 months ago

Internal tracking ticket: P148765181

ashishdhingra commented 2 months ago

Per CloudFormation support, this feature is not available in CFN yet. Opened a new issue https://github.com/aws-cloudformation/cloudformation-coverage-roadmap/issues/2109 in CloudFormation coverage roadmap.

sparrc commented 2 months ago

Hello, this feature is now available in Cloudformation, can it now be added to CDK?

ashishdhingra commented 2 months ago

Hello, this feature is now available in Cloudformation, can it now be added to CDK?

@sparrc 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.

MartinKvL commented 1 month ago

Looks like you guys implemented it: CDK-docs Thanks a lot 👏

ashishdhingra commented 1 month ago

Looks like you guys implemented it: CDK-docs Thanks a lot 👏

@MartinKvL Glad it works for you now. Thanks.

github-actions[bot] commented 1 month ago

Comments on closed issues and PRs are hard for our team to see. If you need help, please open a new issue that references this one.