RetryStrategy Class
Define how Jobs using this JobDefinition respond to different exit conditions.
Example
ts
const jobDefn = new batch.EcsJobDefinition(this, 'JobDefn', {
container: new batch.EcsEc2ContainerDefinition(this, 'containerDefn', {
image: ecs.ContainerImage.fromRegistry('public.ecr.aws/amazonlinux/amazonlinux:latest'),
memory: cdk.Size.mebibytes(2048),
cpu: 256,
}),
retryAttempts: 5,
retryStrategies: [
batch.RetryStrategy.of(batch.Action.EXIT, batch.Reason.CANNOT_PULL_CONTAINER),
],
});
jobDefn.addRetryStrategy(
batch.RetryStrategy.of(batch.Action.EXIT, batch.Reason.SPOT_INSTANCE_RECLAIMED),
);
jobDefn.addRetryStrategy(
batch.RetryStrategy.of(batch.Action.EXIT, batch.Reason.CANNOT_PULL_CONTAINER),
);
jobDefn.addRetryStrategy(
batch.RetryStrategy.of(batch.Action.EXIT, batch.Reason.custom({
onExitCode: '40*',
onReason: 'some reason',
})),
);
python
job_defn = batch.EcsJobDefinition(self, "JobDefn",
container=batch.EcsEc2ContainerDefinition(self, "containerDefn",
image=ecs.ContainerImage.from_registry("public.ecr.aws/amazonlinux/amazonlinux:latest"),
memory=cdk.Size.mebibytes(2048),
cpu=256
),
retry_attempts=5,
retry_strategies=[
batch.RetryStrategy.of(batch.Action.EXIT, batch.Reason.CANNOT_PULL_CONTAINER)
]
)
job_defn.add_retry_strategy(
batch.RetryStrategy.of(batch.Action.EXIT, batch.Reason.SPOT_INSTANCE_RECLAIMED))
job_defn.add_retry_strategy(
batch.RetryStrategy.of(batch.Action.EXIT, batch.Reason.CANNOT_PULL_CONTAINER))
job_defn.add_retry_strategy(
batch.RetryStrategy.of(batch.Action.EXIT, batch.Reason.custom(
on_exit_code="40*",
on_reason="some reason"
)))
java
EcsJobDefinition jobDefn = EcsJobDefinition.Builder.create(this, "JobDefn")
.container(EcsEc2ContainerDefinition.Builder.create(this, "containerDefn")
.image(ContainerImage.fromRegistry("public.ecr.aws/amazonlinux/amazonlinux:latest"))
.memory(Size.mebibytes(2048))
.cpu(256)
.build())
.retryAttempts(5)
.retryStrategies(List.of(RetryStrategy.of(Action.EXIT, Reason.CANNOT_PULL_CONTAINER)))
.build();
jobDefn.addRetryStrategy(RetryStrategy.of(Action.EXIT, Reason.SPOT_INSTANCE_RECLAIMED));
jobDefn.addRetryStrategy(RetryStrategy.of(Action.EXIT, Reason.CANNOT_PULL_CONTAINER));
jobDefn.addRetryStrategy(RetryStrategy.of(Action.EXIT, Reason.custom(CustomReason.builder()
.onExitCode("40*")
.onReason("some reason")
.build())));
csharp
// Install: dotnet add package Amazon.CDK.Lib
var jobDefn = new EcsJobDefinition(this, "JobDefn", new EcsJobDefinitionProps {
Container = new EcsEc2ContainerDefinition(this, "containerDefn", new EcsEc2ContainerDefinitionProps {
Image = ContainerImage.FromRegistry("public.ecr.aws/amazonlinux/amazonlinux:latest"),
Memory = Size.Mebibytes(2048),
Cpu = 256
}),
RetryAttempts = 5,
RetryStrategies = new [] { RetryStrategy.Of(Action.EXIT, Reason.CANNOT_PULL_CONTAINER) }
});
jobDefn.AddRetryStrategy(RetryStrategy.Of(Action.EXIT, Reason.SPOT_INSTANCE_RECLAIMED));
jobDefn.AddRetryStrategy(RetryStrategy.Of(Action.EXIT, Reason.CANNOT_PULL_CONTAINER));
jobDefn.AddRetryStrategy(RetryStrategy.Of(Action.EXIT, Reason.Custom(new CustomReason {
OnExitCode = "40*",
OnReason = "some reason"
})));
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
jobDefn := batch.NewEcsJobDefinition(this, jsii.String("JobDefn"), &EcsJobDefinitionProps{
Container: batch.NewEcsEc2ContainerDefinition(this, jsii.String("containerDefn"), &EcsEc2ContainerDefinitionProps{
Image: ecs.ContainerImage_FromRegistry(jsii.String("public.ecr.aws/amazonlinux/amazonlinux:latest")),
Memory: cdk.Size_Mebibytes(jsii.Number(2048)),
Cpu: jsii.Number(256),
}),
RetryAttempts: jsii.Number(5),
RetryStrategies: []RetryStrategy{
batch.RetryStrategy_Of(batch.Action_EXIT, batch.Reason_CANNOT_PULL_CONTAINER()),
},
})
jobDefn.addRetryStrategy(batch.RetryStrategy_Of(batch.Action_EXIT, batch.Reason_SPOT_INSTANCE_RECLAIMED()))
jobDefn.addRetryStrategy(batch.RetryStrategy_Of(batch.Action_EXIT, batch.Reason_CANNOT_PULL_CONTAINER()))
jobDefn.addRetryStrategy(batch.RetryStrategy_Of(batch.Action_EXIT, batch.Reason_Custom(&CustomReason{
OnExitCode: jsii.String("40*"),
OnReason: jsii.String("some reason"),
})))
Initializer
Properties
Methods
of(action: Action, on: Reason): RetryStrategy // chainable@staticmethod def of(action: Action, on: Reason) -> RetryStrategypublic static RetryStrategy of(Action action, Reason on)public static RetryStrategy Of(Action action, Reason on)func Of(Action Action, On Reason) RetryStrategystatic#Create a new RetryStrategy.