ServiceManagedVolume
Represents a service-managed volume and always configured at launch.
Example
declare const cluster: ecs.Cluster;
const taskDefinition = new ecs.FargateTaskDefinition(this, 'TaskDef');
const container = taskDefinition.addContainer('web', {
image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
portMappings: [{
containerPort: 80,
protocol: ecs.Protocol.TCP,
}],
});
const volume = new ecs.ServiceManagedVolume(this, 'EBSVolume', {
name: 'ebs1',
managedEBSVolume: {
size: Size.gibibytes(15),
volumeType: ec2.EbsDeviceVolumeType.GP3,
fileSystemType: ecs.FileSystemType.XFS,
tagSpecifications: [{
tags: {
purpose: 'production',
},
propagateTags: ecs.EbsPropagatedTagSource.SERVICE,
}],
},
});
volume.mountIn(container, {
containerPath: '/var/lib',
readOnly: false,
});
taskDefinition.addVolume(volume);
const service = new ecs.FargateService(this, 'FargateService', {
cluster,
taskDefinition,
minHealthyPercent: 100,
});
service.addVolume(volume);
# cluster: ecs.Cluster
task_definition = ecs.FargateTaskDefinition(self, "TaskDef")
container = task_definition.add_container("web",
image=ecs.ContainerImage.from_registry("amazon/amazon-ecs-sample"),
port_mappings=[ecs.PortMapping(
container_port=80,
protocol=ecs.Protocol.TCP
)]
)
volume = ecs.ServiceManagedVolume(self, "EBSVolume",
name="ebs1",
managed_ebs_volume=ecs.ServiceManagedEBSVolumeConfiguration(
size=Size.gibibytes(15),
volume_type=ec2.EbsDeviceVolumeType.GP3,
file_system_type=ecs.FileSystemType.XFS,
tag_specifications=[ecs.EBSTagSpecification(
tags={
"purpose": "production"
},
propagate_tags=ecs.EbsPropagatedTagSource.SERVICE
)]
)
)
volume.mount_in(container,
container_path="/var/lib",
read_only=False
)
task_definition.add_volume(volume)
service = ecs.FargateService(self, "FargateService",
cluster=cluster,
task_definition=task_definition,
min_healthy_percent=100
)
service.add_volume(volume)
Cluster cluster;
FargateTaskDefinition taskDefinition = new FargateTaskDefinition(this, "TaskDef");
ContainerDefinition container = taskDefinition.addContainer("web", ContainerDefinitionOptions.builder()
.image(ContainerImage.fromRegistry("amazon/amazon-ecs-sample"))
.portMappings(List.of(PortMapping.builder()
.containerPort(80)
.protocol(Protocol.TCP)
.build()))
.build());
ServiceManagedVolume volume = ServiceManagedVolume.Builder.create(this, "EBSVolume")
.name("ebs1")
.managedEBSVolume(ServiceManagedEBSVolumeConfiguration.builder()
.size(Size.gibibytes(15))
.volumeType(EbsDeviceVolumeType.GP3)
.fileSystemType(FileSystemType.XFS)
.tagSpecifications(List.of(EBSTagSpecification.builder()
.tags(Map.of(
"purpose", "production"))
.propagateTags(EbsPropagatedTagSource.SERVICE)
.build()))
.build())
.build();
volume.mountIn(container, ContainerMountPoint.builder()
.containerPath("/var/lib")
.readOnly(false)
.build());
taskDefinition.addVolume(volume);
FargateService service = FargateService.Builder.create(this, "FargateService")
.cluster(cluster)
.taskDefinition(taskDefinition)
.minHealthyPercent(100)
.build();
service.addVolume(volume);
// Install: dotnet add package Amazon.CDK.Lib
Cluster cluster;
var taskDefinition = new FargateTaskDefinition(this, "TaskDef");
var container = taskDefinition.AddContainer("web", new ContainerDefinitionOptions {
Image = ContainerImage.FromRegistry("amazon/amazon-ecs-sample"),
PortMappings = new [] { new PortMapping {
ContainerPort = 80,
Protocol = Protocol.TCP
} }
});
var volume = new ServiceManagedVolume(this, "EBSVolume", new ServiceManagedVolumeProps {
Name = "ebs1",
ManagedEBSVolume = new ServiceManagedEBSVolumeConfiguration {
Size = Size.Gibibytes(15),
VolumeType = EbsDeviceVolumeType.GP3,
FileSystemType = FileSystemType.XFS,
TagSpecifications = new [] { new EBSTagSpecification {
Tags = new Dictionary<string, string> {
{ "purpose", "production" }
},
PropagateTags = EbsPropagatedTagSource.SERVICE
} }
}
});
volume.MountIn(container, new ContainerMountPoint {
ContainerPath = "/var/lib",
ReadOnly = false
});
taskDefinition.AddVolume(volume);
var service = new FargateService(this, "FargateService", new FargateServiceProps {
Cluster = cluster,
TaskDefinition = taskDefinition,
MinHealthyPercent = 100
});
service.AddVolume(volume);
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var cluster Cluster
taskDefinition := ecs.NewFargateTaskDefinition(this, jsii.String("TaskDef"))
container := taskDefinition.AddContainer(jsii.String("web"), &ContainerDefinitionOptions{
Image: ecs.ContainerImage_FromRegistry(jsii.String("amazon/amazon-ecs-sample")),
PortMappings: []PortMapping{
&PortMapping{
ContainerPort: jsii.Number(80),
Protocol: ecs.Protocol_TCP,
},
},
})
volume := ecs.NewServiceManagedVolume(this, jsii.String("EBSVolume"), &ServiceManagedVolumeProps{
Name: jsii.String("ebs1"),
ManagedEBSVolume: &ServiceManagedEBSVolumeConfiguration{
Size: awscdk.Size_Gibibytes(jsii.Number(15)),
VolumeType: ec2.EbsDeviceVolumeType_GP3,
FileSystemType: ecs.FileSystemType_XFS,
TagSpecifications: []EBSTagSpecification{
&EBSTagSpecification{
Tags: map[string]*string{
"purpose": jsii.String("production"),
},
PropagateTags: ecs.EbsPropagatedTagSource_SERVICE,
},
},
},
})
volume.MountIn(container, &ContainerMountPoint{
ContainerPath: jsii.String("/var/lib"),
ReadOnly: jsii.Boolean(false),
})
taskDefinition.AddVolume(volume)
service := ecs.NewFargateService(this, jsii.String("FargateService"), &FargateServiceProps{
Cluster: Cluster,
TaskDefinition: TaskDefinition,
MinHealthyPercent: jsii.Number(100),
})
service.AddVolume(volume)
Initializer
new ServiceManagedVolume(scope: Construct, id: string, props: ServiceManagedVolumeProps)
ServiceManagedVolume(scope: Construct, id: str, props: ServiceManagedVolumeProps)
new ServiceManagedVolume(Construct scope, String id, ServiceManagedVolumeProps props)
new ServiceManagedVolume(Construct scope, string id, ServiceManagedVolumeProps props)
NewServiceManagedVolume(Scope Construct, Id *string, Props ServiceManagedVolumeProps)
Construct Props
managedEBSVolumeoptionalServiceManagedEBSVolumeConfigurationmanaged_ebs_volumeoptionalServiceManagedEBSVolumeConfigurationmanagedEBSVolumeoptionalServiceManagedEBSVolumeConfigurationManagedEBSVolumeoptionalServiceManagedEBSVolumeConfigurationManagedEBSVolumeoptionalServiceManagedEBSVolumeConfiguration= undefined#This corresponds to the name provided in the ECS TaskDefinition.
Properties
configmay be undefinedServiceManagedEBSVolumeConfigurationconfigmay be undefinedServiceManagedEBSVolumeConfigurationconfigmay be undefinedServiceManagedEBSVolumeConfigurationConfigmay be undefinedServiceManagedEBSVolumeConfigurationConfigmay be undefinedServiceManagedEBSVolumeConfiguration#configuredAtLaunchbooleanconfigured_at_launchboolconfiguredAtLaunchBooleanConfiguredAtLaunchboolConfiguredAtLaunch*bool#Methods
isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#notes · 1 parameter · returns
Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.
Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.
Parameters
xxxxX— Any object.
Returns: true if x is an object created from a class which extends Construct.
mountIn(container: ContainerDefinition, mountPoint: ContainerMountPoint): voiddef mount_in(self, container: ContainerDefinition, mount_point: ContainerMountPoint) -> Nonepublic void mountIn(ContainerDefinition container, ContainerMountPoint mountPoint)public void MountIn(ContainerDefinition container, ContainerMountPoint mountPoint)func MountIn(Container ContainerDefinition, MountPoint ContainerMountPoint)#2 parameters
Parameters
containercontainercontainercontainerContainer— The container to mount the volume on.mountPointmount_pointmountPointmountPointMountPoint— The mounting point details within the container.
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.
1 parameter · returns
Parameters
mixinsmixinsmixinsmixinsMixins— The mixins to apply.
Returns: This construct for chaining