Skip to content
v2.273.0

Volume L2 construct ​

Creates a new EBS Volume in AWS EC2.

Example ​

ts
new ec2.Volume(this, 'Volume', {
  availabilityZone: 'us-east-1a',
  size: Size.gibibytes(125),
  volumeType: ec2.EbsDeviceVolumeType.GP3,
  throughput: 125,
});
python
ec2.Volume(self, "Volume",
    availability_zone="us-east-1a",
    size=Size.gibibytes(125),
    volume_type=ec2.EbsDeviceVolumeType.GP3,
    throughput=125
)
java
Volume.Builder.create(this, "Volume")
        .availabilityZone("us-east-1a")
        .size(Size.gibibytes(125))
        .volumeType(EbsDeviceVolumeType.GP3)
        .throughput(125)
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
new Volume(this, "Volume", new VolumeProps {
    AvailabilityZone = "us-east-1a",
    Size = Size.Gibibytes(125),
    VolumeType = EbsDeviceVolumeType.GP3,
    Throughput = 125
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
ec2.NewVolume(this, jsii.String("Volume"), &VolumeProps{
	AvailabilityZone: jsii.String("us-east-1a"),
	Size: awscdk.Size_Gibibytes(jsii.Number(125)),
	VolumeType: ec2.EbsDeviceVolumeType_GP3,
	Throughput: jsii.Number(125),
})

Initializer ​

ts
new Volume(scope: Construct, id: string, props: VolumeProps)
python
Volume(scope: Construct, id: str, props: VolumeProps)
java
new Volume(Construct scope, String id, VolumeProps props)
csharp
new Volume(Construct scope, string id, VolumeProps props)
go
NewVolume(Scope Construct, Id *string, Props VolumeProps)

Construct Props ​

autoEnableIobooleanauto_enable_ioboolautoEnableIoBooleanAutoEnableIoboolAutoEnableIo*bool= false#
Indicates whether the volume is auto-enabled for I/O operations.
notes

By default, Amazon EBS disables I/O to the volume from attached EC2 instances when it determines that a volume's data is potentially inconsistent. If the consistency of the volume is not a concern, and you prefer that the volume be made available immediately if it's impaired, you can configure the volume to automatically enable I/O.

availabilityZonestringavailability_zonestravailabilityZoneStringAvailabilityZonestringAvailabilityZone*stringrequired#
The Availability Zone in which to create the volume.
enableMultiAttachbooleanenable_multi_attachboolenableMultiAttachBooleanEnableMultiAttachboolEnableMultiAttach*bool= false#
Indicates whether Amazon EBS Multi-Attach is enabled.

See Considerations and limitations for the constraints of multi-attach.

encryptedbooleanencryptedboolencryptedBooleanEncryptedboolEncrypted*bool= false#
Specifies whether the volume should be encrypted.
notes

The effect of setting the encryption state to true depends on the volume origin (new or from a snapshot), starting encryption state, ownership, and whether encryption by default is enabled. For more information, see Encryption by Default in the Amazon Elastic Compute Cloud User Guide.

Encrypted Amazon EBS volumes must be attached to instances that support Amazon EBS encryption. For more information, see Supported Instance Types.

encryptionKeyIKeyencryption_keyIKeyencryptionKeyIKeyEncryptionKeyIKeyEncryptionKeyIKey= The default KMS key for the acco…#
The customer-managed encryption key that is used to encrypt the Volume.
notes · default

The encrypted property must be true if this is provided.

Note: If using an aws-kms.IKey created from a aws-kms.Key.fromKeyArn() here, then the KMS key must have the following in its Key policy; otherwise, the Volume will fail to create.

{
  "Effect": "Allow",
  "Principal": { "AWS": "<arn for your account-user> ex: arn:aws:iam::00000000000:root" },
  "Resource": "*",
  "Action": [
    "kms:DescribeKey",
    "kms:GenerateDataKeyWithoutPlainText",
  ],
  "Condition": {
    "StringEquals": {
      "kms:ViaService": "ec2.<Region>.amazonaws.com", (eg: ec2.us-east-1.amazonaws.com)
      "kms:CallerAccount": "0000000000" (your account ID)
    }
  }
}

Default: The default KMS key for the account, region, and EC2 service is used.

iopsnumberiopsint | floatiopsNumberIopsdoubleIops*float64= None -- Required for io1 and io2…#
The number of I/O operations per second (IOPS) to provision for the volume.
notes · default

The maximum ratio is 50 IOPS/GiB for PROVISIONED_IOPS_SSD, and 500 IOPS/GiB for both PROVISIONED_IOPS_SSD_IO2 and GENERAL_PURPOSE_SSD_GP3. See https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-volume.html for more information.

This parameter is valid only for PROVISIONED_IOPS_SSD, PROVISIONED_IOPS_SSD_IO2 and GENERAL_PURPOSE_SSD_GP3 volumes.

Default: None -- Required for io1 and io2 volumes. The default for gp3 volumes is 3,000 IOPS if omitted.

removalPolicyRemovalPolicyremoval_policyRemovalPolicyremovalPolicyRemovalPolicyRemovalPolicyRemovalPolicyRemovalPolicyRemovalPolicy= RemovalPolicy.RETAIN#
Policy to apply when the volume is removed from the stack.
sizeSizesizeSizesizeSizeSizeSizeSizeSize= If you're creating the volume fr…#
The size of the volume, in GiBs.

You must specify either a snapshot ID or a volume size. See https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-volume.html for details on the allowable size for each type of volume.

default

Default: If you're creating the volume from a snapshot and don't specify a volume size, the default is the snapshot size.

snapshotIdstringsnapshot_idstrsnapshotIdStringSnapshotIdstringSnapshotId*string= The EBS volume is not created fr…#
The snapshot from which to create the volume.

You must specify either a snapshot ID or a volume size.

default

Default: The EBS volume is not created from a snapshot.

throughputnumberthroughputint | floatthroughputNumberThroughputdoubleThroughput*float64= 125 MiB/s. Only valid on gp3 vol…#
The throughput that the volume supports, in MiB/s Takes a minimum of 125 and maximum of 2000.
default

Default: 125 MiB/s. Only valid on gp3 volumes.

volumeInitializationRateSizevolume_initialization_rateSizevolumeInitializationRateSizeVolumeInitializationRateSizeVolumeInitializationRateSize= undefined - The volume initializ…#
Specifies the Amazon EBS Provisioned Rate for Volume Initialization (volume initialization rate), at which to download the snapshot blocks from Amazon S3 to the volume.

Valid range is between 100 and 300 MiB/s.

This parameter is supported only for volumes created from snapshots.

default

Default: undefined - The volume initialization rate is not set.

volumeNamestringvolume_namestrvolumeNameStringVolumeNamestringVolumeName*string= The physical name will be alloca…#
The value of the physicalName property of this resource.
default

Default: The physical name will be allocated by CloudFormation at deployment time

volumeTypeEbsDeviceVolumeTypevolume_typeEbsDeviceVolumeTypevolumeTypeEbsDeviceVolumeTypeVolumeTypeEbsDeviceVolumeTypeVolumeTypeEbsDeviceVolumeType= `EbsDeviceVolumeType.GENERAL_PUR…#
The type of the volume;

what type of storage to use to form the EBS Volume.

default

Default: EbsDeviceVolumeType.GENERAL_PURPOSE_SSD

Properties ​

availabilityZonestringavailability_zonestravailabilityZoneStringAvailabilityZonestringAvailabilityZone*stringrequired#
The availability zone that the EBS Volume is contained within (ex: us-west-2a).
encryptionKeyIKeyencryption_keyIKeyencryptionKeyIKeyEncryptionKeyIKeyEncryptionKeyIKey#
The customer-managed encryption key that is used to encrypt the Volume.
The environment this resource belongs to.
notes

For resources that are created and managed in a Stack (those created by creating new class instances like new Role(), new Bucket(), etc.), this is always the same as the environment of the stack they belong to.

For referenced resources (those obtained from referencing methods like Role.fromRoleArn(), Bucket.fromBucketName(), etc.), they might be different than the stack they were imported into.

nodeNodenodeNodenodeNodeNodeNodeNodeNoderequired#
The tree node.
PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringrequiredstatic#
Uniquely identifies this class.
stackStackstackStackstackStackStackStackStackStackrequired#
The stack in which this resource is defined.
volumeIdstringvolume_idstrvolumeIdStringVolumeIdstringVolumeId*stringrequired#
The EBS Volume's ID.
volumeRefVolumeReferencevolume_refVolumeReferencevolumeRefVolumeReferenceVolumeRefVolumeReferenceVolumeRefVolumeReferencerequired#
A reference to a Volume resource.

Methods ​

applyCrossStackReferenceStrength(strength: ReferenceStrength): voiddef apply_cross_stack_reference_strength(self, strength: ReferenceStrength) -> Nonepublic void applyCrossStackReferenceStrength(ReferenceStrength strength)public void ApplyCrossStackReferenceStrength(ReferenceStrength strength)func ApplyCrossStackReferenceStrength(Strength ReferenceStrength)#
Override the cross-stack reference strength for this resource.
notes · 1 parameter

When set, any cross-stack reference to this resource will use the specified mechanism instead of the global default determined by the @aws-cdk/core:defaultCrossStackReferences context key. This is useful for selectively weakening specific references to avoid the "deadly embrace" problem without changing the app-wide default.

Parameters

  • strengthstrengthstrengthstrengthStrength — - The reference strength to use for this resource.
applyRemovalPolicy(policy: RemovalPolicy): voiddef apply_removal_policy(self, policy: RemovalPolicy) -> Nonepublic void applyRemovalPolicy(RemovalPolicy policy)public void ApplyRemovalPolicy(RemovalPolicy policy)func ApplyRemovalPolicy(Policy RemovalPolicy)#
Apply the given removal policy to this resource.
notes

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).

fromVolumeAttributes(scope: Construct, id: string, attrs: VolumeAttributes): IVolume@staticmethod def from_volume_attributes(scope: Construct, id: str, attrs: VolumeAttributes) -> IVolumepublic static IVolume fromVolumeAttributes(Construct scope, String id, VolumeAttributes attrs)public static IVolume FromVolumeAttributes(Construct scope, string id, VolumeAttributes attrs)func FromVolumeAttributes(Scope Construct, Id *string, Attrs VolumeAttributes) IVolumestatic#
Import an existing EBS Volume into the Stack.
3 parameters

Parameters

  • scopescopescopescopeScope — the scope of the import.
  • ididididId — the ID of the imported Volume in the construct tree.
  • attrsattrsattrsattrsAttrs — the attributes of the imported Volume.
grantAttachVolume(grantee: IGrantable, instances?: IInstanceRef[]): Grantdef grant_attach_volume(self, grantee: IGrantable, instances: typing.Optional[typing.List[IInstanceRef]] = None) -> Grantpublic Grant grantAttachVolume(IGrantable grantee, List<IInstanceRef> instances)public Grant GrantAttachVolume(IGrantable grantee, IInstanceRef[]? instances = null)func GrantAttachVolume(Grantee IGrantable, Instances *[]IInstanceRef) Grant#
[disable-awslint:no-grants].
grantAttachVolumeByResourceTag(grantee: IGrantable, constructs: Construct[], tagKeySuffix?: string): Grantdef grant_attach_volume_by_resource_tag(self, grantee: IGrantable, constructs: typing.List[Construct], tag_key_suffix: typing.Optional[str] = None) -> Grantpublic Grant grantAttachVolumeByResourceTag(IGrantable grantee, List<Construct> constructs, String tagKeySuffix)public Grant GrantAttachVolumeByResourceTag(IGrantable grantee, Construct[] constructs, string? tagKeySuffix = null)func GrantAttachVolumeByResourceTag(Grantee IGrantable, Constructs *[]Construct, TagKeySuffix *string) Grant#
[disable-awslint:no-grants].
grantDetachVolume(grantee: IGrantable, instances?: IInstanceRef[]): Grantdef grant_detach_volume(self, grantee: IGrantable, instances: typing.Optional[typing.List[IInstanceRef]] = None) -> Grantpublic Grant grantDetachVolume(IGrantable grantee, List<IInstanceRef> instances)public Grant GrantDetachVolume(IGrantable grantee, IInstanceRef[]? instances = null)func GrantDetachVolume(Grantee IGrantable, Instances *[]IInstanceRef) Grant#
[disable-awslint:no-grants].
grantDetachVolumeByResourceTag(grantee: IGrantable, constructs: Construct[], tagKeySuffix?: string): Grantdef grant_detach_volume_by_resource_tag(self, grantee: IGrantable, constructs: typing.List[Construct], tag_key_suffix: typing.Optional[str] = None) -> Grantpublic Grant grantDetachVolumeByResourceTag(IGrantable grantee, List<Construct> constructs, String tagKeySuffix)public Grant GrantDetachVolumeByResourceTag(IGrantable grantee, Construct[] constructs, string? tagKeySuffix = null)func GrantDetachVolumeByResourceTag(Grantee IGrantable, Constructs *[]Construct, TagKeySuffix *string) Grant#
[disable-awslint:no-grants].
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#
Checks if `x` is a construct.
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.

isOwnedResource(construct: IConstruct): boolean@staticmethod def is_owned_resource(construct: IConstruct) -> boolpublic static Boolean isOwnedResource(IConstruct construct)public static bool IsOwnedResource(IConstruct construct)func IsOwnedResource(Construct IConstruct) *boolstatic#
Returns true if the construct was created by CDK, and false otherwise.
isResource(construct: IConstruct): boolean@staticmethod def is_resource(construct: IConstruct) -> boolpublic static Boolean isResource(IConstruct construct)public static bool IsResource(IConstruct construct)func IsResource(Construct IConstruct) *boolstatic#
Check whether the given construct is a Resource.
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#
Returns a string representation of this construct.
with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#
Applies one or more mixins to this construct.

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.