-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ecs): support restart policy for container #31228
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.
A comment requesting an exemption should contain the text Exemption Request
. Additionally, if clarification is needed add Clarification Request
to a comment.
050f50b
to
4ee0818
Compare
integ style
4ee0818
to
66a3db5
Compare
sample codes
a48acd7
to
af0dc1b
Compare
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
/** | ||
* Enable a restart policy for a container. | ||
* | ||
* When you set up a restart policy, Amazon ECS can restart the container without needing to replace the task. | ||
* | ||
* @default - false unless `restartIgnoredExitCodes` or `restartAttemptPeriod` is set. | ||
* @see https://docs.aws.amazon.com/AmazonECS/latest/developerguide/container-restart-policy.html | ||
*/ | ||
readonly enableRestartPolicy?: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of having an interface called RestartPolicy
, the flag and other properties are flatly defined.
There are two reasons for this.
The first is to comply with the CDK design guidelines.
Secondly, it was uncomfortable that an empty RestartPolicy
had to be specified to enable the restart policy with the default configuration.
taskDefinition.addContainer('container', {
image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"),
restartPolicy: {},
});
@@ -590,6 +626,8 @@ export class ContainerDefinition extends Construct { | |||
if (props.ulimits) { | |||
this.addUlimits(...props.ulimits); | |||
} | |||
|
|||
this.validateRestartPolicy(props.enableRestartPolicy, props.restartIgnoredExitCodes, props.restartAttemptPeriod); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This validation function is called in the constructor, not in the renderRestartPolicy
function (lines 1550).
The render function is called in the renderContainerDefinition function, which is called by a Lazy method in the TaskDefinition. Therefore, the rendering does not run in the construction phase (even if the construct is created with new ContainerDefinition()
, it still does not run).
However, it is better to run the validation earlier, so the validation is not done in the render function, but in the constructor, which allows it to run earlier. This ensures that the validation is performed when the construct is created with new ContainerDefinition()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you for the contribution!
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Comments on closed issues and PRs are hard for our team to see. |
Issue # (if applicable)
Closes #31127 #31425.
Reason for this change
A restart policy can be specified in CloudFormation, but not in L2.
https://docs.aws.amazon.com/AmazonECS/latest/developerguide/container-restart-policy.html
Description of changes
Add
enableRestartPolicy
and some properties to the container definition.Description of how you validated changes
unit tests and integ tests.
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license