LockSnapshot

Updated at:

Locks a snapshot in compliance mode to prevent accidental or malicious deletion. During the lock period, no user can delete the snapshot.

Operation description

You can also use this operation to reconfigure a locked snapshot. The configurable items depend on the lock mode and lock status:

  • If the snapshot is locked in compliance mode and is in the cool-off period, you can extend or shorten the cool-off period, or extend or shorten the lock duration.

  • If the snapshot is locked in compliance mode and the cool-off period has expired, you can only extend the lock duration.

Note

If you reconfigure a locked snapshot during the cool-off period, the system treats it as a re-lock operation. All lock parameters are reset instead of being adjusted individually.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

ecs:LockSnapshot

update

*Snapshot

acs:ecs:{#regionId}:{#accountId}:snapshot/{#SnapshotId}

None None

Request parameters

Parameter

Type

Required

Description

Example

RegionId

string

Yes

The region ID. You can call the DescribeRegions operation to query the most recent region list.

cn-hangzhou

SnapshotId

string

Yes

The snapshot ID.

s-9dp2qojdpdfmgfmf****

LockMode

string

Yes

The lock mode. Valid values:

  • compliance: Locks the snapshot in compliance mode. A snapshot locked in compliance mode cannot be unlocked by any user and can be deleted only after the lock duration expires. Users cannot shorten the lock duration, but users with the required RAM permissions can extend the lock duration at any time. When you lock a snapshot in compliance mode, you can optionally specify a cool-off period.

compliance

LockDuration

integer

Yes

The lock duration. The snapshot lock automatically expires after the lock duration ends.

Unit: days.

Valid values: 1 to 36500.

1

CoolOffPeriod

integer

Yes

The cool-off period. In compliance mode, you can set a cool-off period or skip the cool-off period to lock the snapshot directly.

During the cool-off period, users with the required RAM permissions can unlock the snapshot, extend or shorten the cool-off period, and extend or shorten the lock duration. The snapshot cannot be deleted during the cool-off period.

After the cool-off period ends, you can only extend the lock duration.

Unit: hours.

Valid values: 0 to 72. A value of 0 indicates that the cool-off period is skipped and the snapshot is locked directly.

If the snapshot has entered the compliance mode lock period, you must set this parameter to 0 to extend the lock duration.

3

DryRun

boolean

No

Specifies whether to perform only a dry run on the request. Valid values:

  • true: Performs only a dry run. The system checks whether required parameters are specified, the request format is valid, and service limits are met. If the request fails the dry run, an error is returned. If the request passes the dry run, the DryRunOperation error code is returned.

  • false: Performs a dry run and executes the request if the request passes the dry run. This is the default value.

false

ClientToken

string

No

The client token that is used to ensure the idempotence of the request. You can use the client to generate the value, but you must ensure that the value is unique among different requests. The client token can contain only ASCII characters and cannot exceed 64 characters in length. For more information, see How to ensure idempotence.

5EC38E7D-389F-1925-ABE2-D7925A8F****

Response elements

Element

Type

Description

Example

object

Schema of Response

RequestId

string

The request ID.

473469C7-AA6F-4DC5-B3DB-A3DC0DE3****

LockedSnapshotInfo

object

The locked snapshot information.

SnapshotId

string

The snapshot ID.

s-9dp2qojdpdfmgfmf****

LockMode

string

The lock mode. Valid values:

  • compliance: Locks the snapshot in compliance mode. A snapshot locked in compliance mode cannot be unlocked by any user and can be deleted only after the lock duration expires. Users cannot shorten the lock duration, but users with the required RAM permissions can extend the lock duration at any time. When you lock a snapshot in compliance mode, you can optionally specify a cool-off period.

compliance

LockStatus

string

The lock status. Valid values:

  • compliance-cooloff: The snapshot is locked in compliance mode and is still in the cool-off period. The snapshot cannot be deleted, but users with the required RAM permissions can unlock the snapshot, extend or shorten the cool-off period, and extend or shorten the lock duration.

  • compliance: The snapshot is locked in compliance mode and the cool-off period has ended. The snapshot cannot be unlocked or deleted, but users with the required RAM permissions can extend the lock duration.

  • expired: The snapshot was locked, but the lock duration has ended and the lock has expired. The snapshot is not locked and can be deleted.

compliance-cooloff

LockCreationTime

string

The time when the snapshot was locked. The time is displayed in the yyyy-MM-ddTHH:mm:ssZ format based on the ISO 8601 standard. UTC+0 is used.

2025-10-15T10:00:00Z

CoolOffPeriod

integer

The cool-off period in compliance mode. Unit: hours.

3

CoolOffPeriodExpiredTime

string

The end time of the cool-off period in compliance mode. The time is displayed in the yyyy-MM-ddTHH:mm:ssZ format based on the ISO 8601 standard. UTC+0 is used.

2025-10-15T13:00:00Z

LockDuration

integer

The lock duration. The snapshot lock automatically expires after the lock duration ends. Unit: days.

1

LockDurationStartTime

string

The start time of the lock duration. The time is displayed in the yyyy-MM-ddTHH:mm:ssZ format based on the ISO 8601 standard. UTC+0 is used.

If you lock a snapshot that is in the progressing state, the lock duration is calculated only after the snapshot enters the accomplished state.

2025-10-15T10:00:00Z

LockExpiredTime

string

The expiration time of the lock. The time is displayed in the yyyy-MM-ddTHH:mm:ssZ format based on the ISO 8601 standard. UTC+0 is used.

2025-10-16T10:00:00Z

Examples

Success response

JSON format

{
  "RequestId": "473469C7-AA6F-4DC5-B3DB-A3DC0DE3****",
  "LockedSnapshotInfo": {
    "SnapshotId": "s-9dp2qojdpdfmgfmf****",
    "LockMode": "compliance",
    "LockStatus": "compliance-cooloff",
    "LockCreationTime": "2025-10-15T10:00:00Z",
    "CoolOffPeriod": 3,
    "CoolOffPeriodExpiredTime": "2025-10-15T13:00:00Z",
    "LockDuration": 1,
    "LockDurationStartTime": "2025-10-15T10:00:00Z",
    "LockExpiredTime": "2025-10-16T10:00:00Z"
  }
}

Error codes

HTTP status code

Error code

Error message

Description

400 InvalidLockMode.Malformed The specified parameter LockMode is invalid. Please check the valid range for this parameter. The specified parameter LockMode is invalid. Please check the valid range for this parameter.
400 InvalidLockDuration.ExceedRetentionDays The specified parameter LockDuration is invalid. The LockDuration should be less than the snapshot RetentionDays. The specified parameter LockDuration is invalid. The LockDuration should be less than the snapshot RetentionDays.
400 InvalidCoolOffPeriod.ExceedLockDuration The specified parameter CoolOffPeriod is invalid. The CoolOffPeriod should be less than the LockDuration. The specified parameter CoolOffPeriod is invalid. The CoolOffPeriod should be less than the LockDuration.
403 InvalidOperation.SnapshotNotAvailable The unavailable snapshot does not support locking. The unavailable snapshot does not support locking.
403 InvalidOperation.ResourceManagedByCloudProduct The current operation is not supported because the resource is managed by a cloud product [%s]. Please contact the relevant cloud product to confirm the reason. The current operation is not supported because the resource is managed by a cloud product. Please contact the relevant cloud product to confirm the reason.
403 InvalidOperation.LockSharedSnapshotUnsupported The shared snapshot does not support locking. The shared snapshot does not support locking.
403 InvalidOperation.CoolOffPeriodExpired The snapshot is locked in compliance mode; and the cool-off period has expired. The current operation is not supported.
404 InvalidSnapshotId.NotFound The specified snapshot is not found. The specified Snapshot does not exist.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.