volume_attachments
Creates, updates, deletes or gets a volume_attachment resource or lists volume_attachments in a region
Overview
| Name | volume_attachments |
| Type | Resource |
| Description | Attaches an Amazon EBS volume to a running instance and exposes it to the instance with the specified device name.Before this resource can be deleted (and therefore the volume detached), you must first unmount the volume in the instance. Failure to do so results in the volume being stuck in the busy state while it is trying to detach, which could possibly damage the file system or the data it contains.If an Amazon EBS volume is the root device of an instance, it cannot be detached while the instance is in the "running" state. To detach the root volume, stop the instance first. If the root volume is detached from an instance with an MKT product code, then the product codes from that volume are no longer associated with the instance. |
| Id | awscc.ec2.volume_attachments |
Fields
- get (all properties)
- list (identifiers only)
| Name | Datatype | Description |
|---|---|---|
volume_id | string | The ID of the Amazon EBS volume. The volume and instance must be within the same Availability Zone. This value can be a reference to an AWS::EC2::Volume resource, or it can be the volume ID of an existing Amazon EBS volume. |
instance_id | string | The ID of the instance to which the volume attaches. This value can be a reference to an AWS::EC2::Instance resource, or it can be the physical ID of an existing EC2 instance. |
device | string | The device name (for example, /dev/sdh or xvdh). |
region | string | AWS region. |
| Name | Datatype | Description |
|---|---|---|
volume_id | string | The ID of the Amazon EBS volume. The volume and instance must be within the same Availability Zone. This value can be a reference to an AWS::EC2::Volume resource, or it can be the volume ID of an existing Amazon EBS volume. |
instance_id | string | The ID of the instance to which the volume attaches. This value can be a reference to an AWS::EC2::Instance resource, or it can be the physical ID of an existing EC2 instance. |
region | string | AWS region. |
For more information, see AWS::EC2::VolumeAttachment.
Methods
| Name | Resource | Accessible by | Required Params |
|---|---|---|---|
create_resource | volume_attachments | INSERT | VolumeId, InstanceId, region |
delete_resource | volume_attachments | DELETE | Identifier, region |
list_resources | volume_attachments_list_only | SELECT | region |
get_resource | volume_attachments | SELECT | Identifier, region |
SELECT examples
- get (all properties)
- list (identifiers only)
Gets all properties from an individual volume_attachment.
SELECT
region,
volume_id,
instance_id,
device
FROM awscc.ec2.volume_attachments
WHERE
region = '{{ region }}' AND
Identifier = '{{ volume_id }}|{{ instance_id }}';
Lists all volume_attachments in a region.
SELECT
region,
volume_id,
instance_id
FROM awscc.ec2.volume_attachments_list_only
WHERE
region = '{{ region }}';
INSERT example
Use the following StackQL query and manifest file to create a new volume_attachment resource, using stack-deploy.
- Required Properties
- All Properties
- Manifest
/*+ create */
INSERT INTO awscc.ec2.volume_attachments (
VolumeId,
InstanceId,
region
)
SELECT
'{{ volume_id }}',
'{{ instance_id }}',
'{{ region }}'
RETURNING
ErrorCode,
EventTime,
Identifier,
Operation,
OperationStatus,
RequestToken,
ResourceModel,
RetryAfter,
StatusMessage,
TypeName
;
/*+ create */
INSERT INTO awscc.ec2.volume_attachments (
VolumeId,
InstanceId,
Device,
region
)
SELECT
'{{ volume_id }}',
'{{ instance_id }}',
'{{ device }}',
'{{ region }}'
RETURNING
ErrorCode,
EventTime,
Identifier,
Operation,
OperationStatus,
RequestToken,
ResourceModel,
RetryAfter,
StatusMessage,
TypeName
;
version: 1
name: stack name
description: stack description
providers:
- aws
globals:
- name: region
value: '{{ vars.AWS_REGION }}'
resources:
- name: volume_attachment
props:
- name: volume_id
value: '{{ volume_id }}'
- name: instance_id
value: '{{ instance_id }}'
- name: device
value: '{{ device }}'
DELETE example
/*+ delete */
DELETE FROM awscc.ec2.volume_attachments
WHERE
Identifier = '{{ volume_id }}|{{ instance_id }}' AND
region = '{{ region }}'
RETURNING
ErrorCode,
EventTime,
Identifier,
Operation,
OperationStatus,
RequestToken,
ResourceModel,
RetryAfter,
StatusMessage,
TypeName
;
Additional Parameters
Mutable resources in the Cloud Control provider support additional optional parameters which can be supplied with INSERT, UPDATE, or DELETE operations. These include:
| Parameter | Description |
|---|---|
ClientToken | A unique identifier to ensure the idempotency of the resource request.This allows the provider to accurately distinguish between retries and new requests.A client token is valid for 36 hours once used. After that, a resource request with the same client token is treated as a new request. If you do not specify a client token, one is generated for inclusion in the request. |
RoleArn | The ARN of the IAM role used to perform this resource operation.The role specified must have the permissions required for this operation.If you do not specify a role, a temporary session is created using your AWS user credentials. |
TypeVersionId | For private resource types, the type version to use in this resource operation.If you do not specify a resource version, the default version is used. |
Permissions
To operate on the volume_attachments resource, the following permissions are required:
- Create
- Read
- Delete
- List
ec2:AttachVolume,
ec2:DescribeVolumes
ec2:DescribeVolumes
ec2:DetachVolume,
ec2:DescribeVolumes
ec2:DescribeVolumes