# RestartPolicyProperty

You can enable a restart policy for each container defined in your task definition, to overcome transient failures faster and maintain task availability.

When you enable a restart policy for a container, Amazon ECS can restart the container if it exits, without needing to replace the task. For more information, see [Restart individual containers in Amazon ECS tasks with container restart policies](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/container-restart-policy.html) in the *Amazon Elastic Container Service Developer Guide* .

- Source: Generated at build time
- Type last changed: v2.157.0 · 10 Sep 2024

## Example

TypeScript:

```ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import { aws_ecs as ecs } from 'aws-cdk-lib';
const restartPolicyProperty: ecs.CfnTaskDefinition.RestartPolicyProperty = {
  enabled: false,
  ignoredExitCodes: [123],
  restartAttemptPeriod: 123,
};
```

Python:

```python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
from aws_cdk import aws_ecs as ecs

restart_policy_property = ecs.CfnTaskDefinition.RestartPolicyProperty(
    enabled=False,
    ignored_exit_codes=[123],
    restart_attempt_period=123
)
```

Java:

```java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.services.ecs.*;

RestartPolicyProperty restartPolicyProperty = RestartPolicyProperty.builder()
        .enabled(false)
        .ignoredExitCodes(List.of(123))
        .restartAttemptPeriod(123)
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK.AWS.ECS;

var restartPolicyProperty = new RestartPolicyProperty {
    Enabled = false,
    IgnoredExitCodes = new [] { 123 },
    RestartAttemptPeriod = 123
};
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"

restartPolicyProperty := &RestartPolicyProperty{
	Enabled: jsii.Boolean(false),
	IgnoredExitCodes: []interface{}{
		jsii.Number(123),
	},
	RestartAttemptPeriod: jsii.Number(123),
}
```

## Properties

- `enabled`: boolean | [IResolvable](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) — Specifies whether a restart policy is enabled for the container.

- `ignoredExitCodes`: number[] | [IResolvable](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) — A list of exit codes that Amazon ECS will ignore and not attempt a restart on.

  You can specify a maximum of 50 container exit codes. By default, Amazon ECS does not ignore any exit codes.

- `restartAttemptPeriod`: number — A period of time (in seconds) that the container must run for before a restart can be attempted.

  A container can be restarted only once every `restartAttemptPeriod` seconds. If a container isn't able to run for this time period and exits early, it will not be restarted. You can set a minimum `restartAttemptPeriod` of 60 seconds and a maximum `restartAttemptPeriod` of 1800 seconds. By default, a container must run for 300 seconds before it can be restarted.
