Class Volume

java.lang.Object
software.amazon.jsii.JsiiObject
software.constructs.Construct
software.amazon.awscdk.Resource
software.amazon.awscdk.services.ec2.Volume
All Implemented Interfaces:
IResource, IVolume, software.amazon.jsii.JsiiSerializable, software.constructs.IConstruct, software.constructs.IDependable

@Generated(value="jsii-pacmak/1.104.0 (build e79254c)", date="2024-11-21T06:34:07.231Z") @Stability(Stable) public class Volume extends Resource implements IVolume
Creates a new EBS Volume in AWS EC2.

Example:

 Instance instance;
 Role role;
 Volume volume = Volume.Builder.create(this, "Volume")
         .availabilityZone("us-west-2a")
         .size(Size.gibibytes(500))
         .encrypted(true)
         .build();
 volume.grantAttachVolume(role, List.of(instance));
 
  • Constructor Details

    • Volume

      protected Volume(software.amazon.jsii.JsiiObjectRef objRef)
    • Volume

      protected Volume(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
    • Volume

      @Stability(Stable) public Volume(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull VolumeProps props)
      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
      props - This parameter is required.
  • Method Details

    • fromVolumeAttributes

      @Stability(Stable) @NotNull public static IVolume fromVolumeAttributes(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull VolumeAttributes attrs)
      Import an existing EBS Volume into the Stack.

      Parameters:
      scope - the scope of the import. This parameter is required.
      id - the ID of the imported Volume in the construct tree. This parameter is required.
      attrs - the attributes of the imported Volume. This parameter is required.
    • grantAttachVolume

      @Stability(Stable) @NotNull public Grant grantAttachVolume(@NotNull IGrantable grantee, @Nullable List<IInstance> instances)
      Grants permission to attach this Volume to an instance.

      CAUTION: Granting an instance permission to attach to itself using this method will lead to an unresolvable circular reference between the instance role and the instance. Use IVolume.grantAttachVolumeToSelf to grant an instance permission to attach this volume to itself.

      Specified by:
      grantAttachVolume in interface IVolume
      Parameters:
      grantee - This parameter is required.
      instances -
    • grantAttachVolume

      @Stability(Stable) @NotNull public Grant grantAttachVolume(@NotNull IGrantable grantee)
      Grants permission to attach this Volume to an instance.

      CAUTION: Granting an instance permission to attach to itself using this method will lead to an unresolvable circular reference between the instance role and the instance. Use IVolume.grantAttachVolumeToSelf to grant an instance permission to attach this volume to itself.

      Specified by:
      grantAttachVolume in interface IVolume
      Parameters:
      grantee - This parameter is required.
    • grantAttachVolumeByResourceTag

      @Stability(Stable) @NotNull public Grant grantAttachVolumeByResourceTag(@NotNull IGrantable grantee, @NotNull List<software.constructs.Construct> constructs, @Nullable String tagKeySuffix)
      Grants permission to attach the Volume by a ResourceTag condition.

      If you are looking to grant an Instance, AutoScalingGroup, EC2-Fleet, SpotFleet, ECS host, etc the ability to attach this volume to itself then this is the method you want to use.

      This is implemented by adding a Tag with key VolumeGrantAttach-<suffix> to the given constructs and this Volume, and then conditioning the Grant such that the grantee is only given the ability to AttachVolume if both the Volume and the destination Instance have that tag applied to them.

      Specified by:
      grantAttachVolumeByResourceTag in interface IVolume
      Parameters:
      grantee - This parameter is required.
      constructs - This parameter is required.
      tagKeySuffix -
    • grantAttachVolumeByResourceTag

      @Stability(Stable) @NotNull public Grant grantAttachVolumeByResourceTag(@NotNull IGrantable grantee, @NotNull List<software.constructs.Construct> constructs)
      Grants permission to attach the Volume by a ResourceTag condition.

      If you are looking to grant an Instance, AutoScalingGroup, EC2-Fleet, SpotFleet, ECS host, etc the ability to attach this volume to itself then this is the method you want to use.

      This is implemented by adding a Tag with key VolumeGrantAttach-<suffix> to the given constructs and this Volume, and then conditioning the Grant such that the grantee is only given the ability to AttachVolume if both the Volume and the destination Instance have that tag applied to them.

      Specified by:
      grantAttachVolumeByResourceTag in interface IVolume
      Parameters:
      grantee - This parameter is required.
      constructs - This parameter is required.
    • grantDetachVolume

      @Stability(Stable) @NotNull public Grant grantDetachVolume(@NotNull IGrantable grantee, @Nullable List<IInstance> instances)
      Grants permission to detach this Volume from an instance CAUTION: Granting an instance permission to detach from itself using this method will lead to an unresolvable circular reference between the instance role and the instance.

      Use IVolume.grantDetachVolumeFromSelf to grant an instance permission to detach this volume from itself.

      Specified by:
      grantDetachVolume in interface IVolume
      Parameters:
      grantee - This parameter is required.
      instances -
    • grantDetachVolume

      @Stability(Stable) @NotNull public Grant grantDetachVolume(@NotNull IGrantable grantee)
      Grants permission to detach this Volume from an instance CAUTION: Granting an instance permission to detach from itself using this method will lead to an unresolvable circular reference between the instance role and the instance.

      Use IVolume.grantDetachVolumeFromSelf to grant an instance permission to detach this volume from itself.

      Specified by:
      grantDetachVolume in interface IVolume
      Parameters:
      grantee - This parameter is required.
    • grantDetachVolumeByResourceTag

      @Stability(Stable) @NotNull public Grant grantDetachVolumeByResourceTag(@NotNull IGrantable grantee, @NotNull List<software.constructs.Construct> constructs, @Nullable String tagKeySuffix)
      Grants permission to detach the Volume by a ResourceTag condition.

      This is implemented via the same mechanism as IVolume.grantAttachVolumeByResourceTag, and is subject to the same conditions.

      Specified by:
      grantDetachVolumeByResourceTag in interface IVolume
      Parameters:
      grantee - This parameter is required.
      constructs - This parameter is required.
      tagKeySuffix -
    • grantDetachVolumeByResourceTag

      @Stability(Stable) @NotNull public Grant grantDetachVolumeByResourceTag(@NotNull IGrantable grantee, @NotNull List<software.constructs.Construct> constructs)
      Grants permission to detach the Volume by a ResourceTag condition.

      This is implemented via the same mechanism as IVolume.grantAttachVolumeByResourceTag, and is subject to the same conditions.

      Specified by:
      grantDetachVolumeByResourceTag in interface IVolume
      Parameters:
      grantee - This parameter is required.
      constructs - This parameter is required.
    • validateProps

      @Stability(Stable) protected void validateProps(@NotNull VolumeProps props)
      Parameters:
      props - This parameter is required.
    • getAvailabilityZone

      @Stability(Stable) @NotNull public String getAvailabilityZone()
      The availability zone that the EBS Volume is contained within (ex: us-west-2a).
      Specified by:
      getAvailabilityZone in interface IVolume
    • getVolumeId

      @Stability(Stable) @NotNull public String getVolumeId()
      The EBS Volume's ID.
      Specified by:
      getVolumeId in interface IVolume
    • getEncryptionKey

      @Stability(Stable) @Nullable public IKey getEncryptionKey()
      The customer-managed encryption key that is used to encrypt the Volume.
      Specified by:
      getEncryptionKey in interface IVolume