Skip to content
v2.278.0

LifecycleConfiguration Struct ​

LifecycleConfiguration lets you manage the lifecycle of runtime sessions and resources in AgentCore Runtime.

This configuration helps optimize resource utilization by automatically cleaning up idle sessions and preventing long-running instances from consuming resources indefinitely.

Example ​

ts
const repository = new ecr.Repository(this, "TestRepository", {
  repositoryName: "test-agent-runtime",
});

const agentRuntimeArtifact = agentcore.AgentRuntimeArtifact.fromEcrRepository(repository, "v1.0.0");

new agentcore.Runtime(this, 'test-runtime', {
  runtimeName: 'test_runtime',
  agentRuntimeArtifact: agentRuntimeArtifact,
  lifecycleConfiguration: {
    idleRuntimeSessionTimeout: Duration.minutes(10),
    maxLifetime: Duration.hours(4),
  },
});
python
repository = ecr.Repository(self, "TestRepository",
    repository_name="test-agent-runtime"
)

agent_runtime_artifact = agentcore.AgentRuntimeArtifact.from_ecr_repository(repository, "v1.0.0")

agentcore.Runtime(self, "test-runtime",
    runtime_name="test_runtime",
    agent_runtime_artifact=agent_runtime_artifact,
    lifecycle_configuration=agentcore.LifecycleConfiguration(
        idle_runtime_session_timeout=Duration.minutes(10),
        max_lifetime=Duration.hours(4)
    )
)
java
Repository repository = Repository.Builder.create(this, "TestRepository")
        .repositoryName("test-agent-runtime")
        .build();

AgentRuntimeArtifact agentRuntimeArtifact = AgentRuntimeArtifact.fromEcrRepository(repository, "v1.0.0");

Runtime.Builder.create(this, "test-runtime")
        .runtimeName("test_runtime")
        .agentRuntimeArtifact(agentRuntimeArtifact)
        .lifecycleConfiguration(LifecycleConfiguration.builder()
                .idleRuntimeSessionTimeout(Duration.minutes(10))
                .maxLifetime(Duration.hours(4))
                .build())
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
var repository = new Repository(this, "TestRepository", new RepositoryProps {
    RepositoryName = "test-agent-runtime"
});

var agentRuntimeArtifact = AgentRuntimeArtifact.FromEcrRepository(repository, "v1.0.0");

new Runtime(this, "test-runtime", new RuntimeProps {
    RuntimeName = "test_runtime",
    AgentRuntimeArtifact = agentRuntimeArtifact,
    LifecycleConfiguration = new LifecycleConfiguration {
        IdleRuntimeSessionTimeout = Duration.Minutes(10),
        MaxLifetime = Duration.Hours(4)
    }
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
repository := ecr.NewRepository(this, jsii.String("TestRepository"), &RepositoryProps{
	RepositoryName: jsii.String("test-agent-runtime"),
})

agentRuntimeArtifact := agentcore.AgentRuntimeArtifact_FromEcrRepository(repository, jsii.String("v1.0.0"))

agentcore.NewRuntime(this, jsii.String("test-runtime"), &RuntimeProps{
	RuntimeName: jsii.String("test_runtime"),
	AgentRuntimeArtifact: agentRuntimeArtifact,
	LifecycleConfiguration: &LifecycleConfiguration{
		IdleRuntimeSessionTimeout: awscdk.Duration_Minutes(jsii.Number(10)),
		MaxLifetime: awscdk.Duration_Hours(jsii.Number(4)),
	},
})

Properties ​

idleRuntimeSessionTimeoutoptionalDurationidle_runtime_session_timeoutoptionalDurationidleRuntimeSessionTimeoutoptionalDurationIdleRuntimeSessionTimeoutoptionalDurationIdleRuntimeSessionTimeoutoptionalDuration #
Timeout in seconds for idle runtime sessions.

Default: undefined - service default setting is 900 seconds (15 minutes)

When a session remains idle for this duration, it will be automatically terminated.

maxLifetimeoptionalDurationmax_lifetimeoptionalDurationmaxLifetimeoptionalDurationMaxLifetimeoptionalDurationMaxLifetimeoptionalDuration #
Maximum lifetime for the instance in seconds.

Default: undefined - service default setting is 28800 seconds (8 hours)

Once reached, instances will be automatically terminated and replaced.