Volume L2 construct
Creates a new EBS Volume in AWS EC2.
Example
new ec2.Volume(this, 'Volume', {
availabilityZone: 'us-east-1a',
size: Size.gibibytes(125),
volumeType: ec2.EbsDeviceVolumeType.GP3,
throughput: 125,
});
ec2.Volume(self, "Volume",
availability_zone="us-east-1a",
size=Size.gibibytes(125),
volume_type=ec2.EbsDeviceVolumeType.GP3,
throughput=125
)
Volume.Builder.create(this, "Volume")
.availabilityZone("us-east-1a")
.size(Size.gibibytes(125))
.volumeType(EbsDeviceVolumeType.GP3)
.throughput(125)
.build();
// 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
});
// 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
new Volume(scope: Construct, id: string, props: VolumeProps)
Volume(scope: Construct, id: str, props: VolumeProps)
new Volume(Construct scope, String id, VolumeProps props)
new Volume(Construct scope, string id, VolumeProps props)
NewVolume(Scope Construct, Id *string, Props VolumeProps)
Construct Props
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#enableMultiAttachbooleanenable_multi_attachboolenableMultiAttachBooleanEnableMultiAttachboolEnableMultiAttach*bool= false#See Considerations and limitations for the constraints of multi-attach.
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…#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.
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#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…#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…#default
Default: 125 MiB/s. Only valid on gp3 volumes.
volumeInitializationRateSizevolume_initialization_rateSizevolumeInitializationRateSizeVolumeInitializationRateSizeVolumeInitializationRateSize= undefined - The volume initializ…#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…#default
Default: The physical name will be allocated by CloudFormation at deployment time
volumeTypeEbsDeviceVolumeTypevolume_typeEbsDeviceVolumeTypevolumeTypeEbsDeviceVolumeTypeVolumeTypeEbsDeviceVolumeTypeVolumeTypeEbsDeviceVolumeType= `EbsDeviceVolumeType.GENERAL_PUR…#what type of storage to use to form the EBS Volume.
default
Default: EbsDeviceVolumeType.GENERAL_PURPOSE_SSD
Properties
availabilityZonestringavailability_zonestravailabilityZoneStringAvailabilityZonestringAvailabilityZone*stringrequired#envResourceEnvironmentenvResourceEnvironmentenvResourceEnvironmentEnvResourceEnvironmentEnvResourceEnvironmentrequired#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.
PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringrequiredstatic#volumeRefVolumeReferencevolume_refVolumeReferencevolumeRefVolumeReferenceVolumeRefVolumeReferenceVolumeRefVolumeReferencerequired#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)#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)#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#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#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#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#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#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.
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#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#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.