Delete a map item
Deleting an object or object version without a lock
An object or object version for which the lock has not been set (e.g., because object lock is not enabled in the bucket) can be deleted without any additional confirmation.
Note
To delete an object with an incomplete multipart upload, follow these instructions.
The minimum required role is storage.editor
.
To delete an object:
-
In the management console
, select the folder. -
Select Object Storage.
-
Click the name of the bucket you need.
-
To delete a single object, click
to the right of the object name; in the menu that opens, click Delete.To do the same with multiple objects, select them in the list and click Delete at the bottom of the screen.
Note
You can delete a folder with objects. This is an asynchronous operation. Once run, objects are gradually deleted from the bucket instead of all at once. During this time, you can perform other operations in the management console, including upload new objects to the folder being deleted. For more information, see Folder.
-
In the window that opens, click Delete.
In the management console, information about the number of objects in a bucket and the used space is updated with a few minutes' delay.
If you do not have the AWS CLI yet, install and configure it.
In the terminal, run the aws s3api delete-object
command:
aws s3api delete-object \
--endpoint-url https://storage.yandexcloud.net \
--bucket <bucket_name> \
--key <object_key>
Where:
--bucket
: Name of your bucket--key
: Object key
To delete multiple objects at once, provide the keys of these objects in the --delete
parameter:
-
Bash:
aws s3api delete-objects \ --endpoint-url=https://storage.yandexcloud.net \ --bucket <bucket_name> \ --delete '{"Objects":[{"Key":"<object_1_key>"},{"Key":"<object_2_key>"},...,{"Key":"<object_n_key>"}]}'
-
PowerShell:
aws s3api delete-objects ` --endpoint-url=https://storage.yandexcloud.net ` --bucket <bucket_name> ` --delete '{\"Objects\":[{\"Key\":\"<object_1_key>\"},{\"Key\":\"<object_2_key>\"},...,{\"Key\":\"<object_n_key>\"}]}'
Where:
--bucket
: Bucket name<object_1_key>
,<object_2_key>
,<object_n_key>
: Keys of the objects to be deleted
Result:
{
"Deleted": [
{
"Key": "<object_1_key>",
"VersionId": "null"
},
{
"Key": "<object_2_key>",
"VersionId": "null"
}
...
{
"Key": "<object_n_key>",
"VersionId": "null"
}
]
}
You can specify objects for deletion using a query template in JMESPath format. To delete objects using a query template, run the following command:
-
Bash:
aws s3api list-objects \ --endpoint-url https://storage.yandexcloud.net \ --bucket <bucket_name> \ --query '<query>' \ --output text | xargs -I {} aws s3api delete-object --endpoint-url https://storage.yandexcloud.net --bucket <bucket_name> --key {}
Where:
--bucket
: Bucket name--query
: Query in JMESPath format
Here is an example of the command that deletes from
sample-bucket
all objects located in thescreenshots
folder whose filenames start with20231002
:aws s3api list-objects \ --endpoint-url https://storage.yandexcloud.net \ --bucket sample-bucket \ --query 'Contents[?starts_with(Key, `screenshots/20231002`) == `true`].[Key]' \ --output text | xargs -I {} aws s3api delete-object --endpoint-url https://storage.yandexcloud.net --bucket sample-bucket --key {}
-
PowerShell:
Foreach($x in (aws s3api list-objects ` --endpoint-url https://storage.yandexcloud.net ` --bucket <bucket_name> ` --query '<query>' ` --output text)) ` {aws s3api delete-object --endpoint-url https://storage.yandexcloud.net --bucket <bucket_name> --key $x}
Where:
--bucket
: Bucket name--query
: Query in JMESPath format
Here is an example of the command that deletes from
sample-bucket
all objects located in thescreenshots
folder whose filenames start with20231002
:Foreach($x in (aws s3api list-objects ` --endpoint-url https://storage.yandexcloud.net ` --bucket sample-bucket ` --query 'Contents[?starts_with(Key, `screenshots/20231002`) == `true`].[Key]' ` --output text)) ` {aws s3api delete-object --endpoint-url https://storage.yandexcloud.net --bucket sample-bucket --key $x}
Note
Terraform uses a service account to interact with Object Storage. Assign to the service account the required role, e.g., storage.admin
, for the folder where you are going to create resources.
Terraform
For more information about the provider resources, see the documentation on the Terraform
If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.
If you don't have Terraform, install it and configure the Yandex Cloud provider.
To delete an object created with Terraform from a bucket:
-
Open the Terraform configuration file and delete the fragment with the object description.
Example object description in a Terraform configuration... resource "yandex_storage_object" "cute-cat-picture" { access_key = "YCAJEX9Aw2ge********-w-lJ" secret_key = "YCONxG7rSdzVF9UMxLA_NRy5VbKzKlqZ********" bucket = "cat-pictures" key = "cute-cat" source = "/images/cats/cute-cat.jpg" } ...
-
In the command line, go to the directory with the Terraform configuration file.
-
Check the configuration using this command:
terraform validate
If the configuration is correct, you will get this message:
Success! The configuration is valid.
-
Run this command:
terraform plan
The terminal will display a list of resources with parameters. No changes will be made at this step. If the configuration contains any errors, Terraform will point them out.
-
Apply the configuration changes:
terraform apply
-
Confirm the changes: type
yes
into the terminal and press Enter.You can check the changes in the management console
.
Deleting an object version with an object lock
If object lock is enabled in the bucket, some or all users can be forbidden to delete an object version.
To check whether lock has been put and delete the object version when possible:
-
If you do not have the AWS CLI yet, install and configure it.
-
Get information about an object lock:
aws --endpoint-url=https://storage.yandexcloud.net \ s3api head-object \ --bucket <bucket_name> \ --key <object_key> \ --version-id <version_ID>
Where:
--bucket
: Name of your bucket--key
: Object key--version-id
: Object version ID
If an object version is locked, the following command returns the lock details:
{ ... "ObjectLockMode": "<type_of_object_lock_with_retention_period>", "ObjectLockRetainUntilDate": "<date_and_time>", "ObjectLockLegalHoldStatus": "<status_of_legal_hold>", ... }
Where:
-
ObjectLockMode
: Type of object lock set for a certain period:GOVERNANCE
: Object lock with a predefined retention period that can be managed. Users with thestorage.admin
role can delete an object version.COMPLIANCE
: Object lock with a predefined retention period with strict compliance. You cannot delete an object version.
-
ObjectLockRetainUntilDate
: Date and time until which the object will be locked, specified in any format described in the HTTP standard , e.g.,Mon, 12 Dec 2022 09:00:00 GMT
. -
ObjectLockLegalHoldStatus
: Status of legal hold:ON
: Enabled. You cannot delete an object version. To remove a lock, a user must have thestorage.uploader
role.OFF
: Disabled.
If the object version is not locked, these fields will not be displayed, and you can delete the object version just as you would do in case of an unlocked version, following this guide.
-
If you have the
storage.admin
role and"ObjectLockMode": "GOVERNANCE"
is set, delete an object version:aws --endpoint-url=https://storage.yandexcloud.net \ s3api delete-object \ --bucket <bucket_name> \ --key <object_key> \ --version-id <version_ID> \ --bypass-governance-retention
Where:
--bucket
: Name of your bucket.--key
: Object key.--version-id
: Object version ID.--bypass-governance-retention
: Flag that shows that a lock is bypassed.
- To get the details of the lock applied to an object version, use the getObjectRetention (retention) and getObjectLegalHold (legal hold) S3 API methods.
- If you only have the
GOVERNANCE
retention set and you have thestorage.admin
role, delete the object version using the delete S3 API method. In your request, specify the version ID and theX-Amz-Bypass-Governance-Retention
header to confirm lock bypass.