如何修复 GCP CommandException 中的错误:"lifecycle" command spanning providers not allowed
How to fix the error in GCP CommandException: "lifecycle" command spanning providers not allowed
我正在学习GCP。我有一个名为 welynx-test1_copy 的桶
我想为其设置一个生命周期策略,以便在 23 天后删除存储桶,按照命令帮助我在 CLI 中执行了以下命令:
xenonxie@cloudshell:~ (rock-perception-263016)$ gsutil ls
gs://rock-perception-263016.appspot.com/
gs://staging.rock-perception-263016.appspot.com/
gs://welynx-test1/
gs://welynx-test1_copy/
所以你可以看到存储桶存在。
设置以下政策会出错:
xenonxie@cloudshell:~ (rock-perception-263016)$ gsutil lifecycle set {"rule": [{"action": {"type": "Delete"}, "condition": {"age": 23}}]} gs://welynx-test1_copy
CommandException: "lifecycle" command spanning providers not allowed.
我尝试遵循 help
中的语法,如下所示:
xenonxie@cloudshell:~ (rock-perception-263016)$ gsutil lifecycle
--help NAME lifecycle - Get or set lifecycle configuration for a bucket
SYNOPSIS gsutil lifecycle get url gsutil lifecycle set
config-json-file url...
DESCRIPTION The lifecycle command can be used to get or set
lifecycle management policies for the given bucket(s). This command
is supported for buckets only, not objects. For more information on
object lifecycle management, please see the Google Cloud Storage
docs <https://cloud.google.com/storage/docs/lifecycle>
_.
The lifecycle command has two sub-commands: GET Gets the lifecycle
configuration for a given bucket. You can get the lifecycle
configuration for only one bucket at a time. The output can be
redirected into a file, edited and then updated via the set
sub-command.
SET Sets the lifecycle configuration on one or more buckets. The
config-json-file specified on the command line should be a path to a
local file containing the lifecycle configuration JSON document.
EXAMPLES The following lifecycle configuration JSON document
specifies that all objects in this bucket that are more than 365
days old will be deleted automatically:
{
"rule":
[
{
"action": {"type": "Delete"},
"condition": {"age": 365}
}
]
}
The following (empty) lifecycle configuration JSON document removes
all lifecycle configuration for a bucket:
{}
我在这里遗漏了什么,我该如何解决?非常感谢。
你的命令的问题是你把规则放在了你想要 运行 的命令而不是配置文件中。
方法是:
- 使用生命周期配置规则创建一个 JSON 文件
- 像这样使用生命周期集
gsutil lifecycle set [CONFIG_FILE] gs://[BUCKET_NAME]
基本上,你可以像你给出的例子那样输入:
{
"rule":
[
{
"action": {"type": "Delete"},
"condition": {"age": 23}
}
]
}
并使用您创建的 JSON 文件更改 CONFIG_FILE。
显然,gsutil
检查存储桶名称是否属于 google 在 它检查生命周期文件是否存在之前:
❯ gsutil lifecycle set foo bar gs://baz
CommandException: "lifecycle" command spanning providers not allowed.
❯ gsutil lifecycle set foo gs://baz
AccessDeniedException: 403 user@domain.com does not have storage.buckets.get access to baz.
❯ gsutil lifecycle set foo gs://a-real-bucket-name
Setting lifecycle configuration on gs://a-real-bucket-name/...
ArgumentException: JSON lifecycle data could not be loaded from:
因此,如果您在第五个位置提供的不是 google 控制的桶:
gsutil lifecycle set file.json THIS_ARGUMENT
您将看到与该问题相关的错误 而不是 与该文件相关的错误。
这也让我感到困惑,我认为 google 可以对 gsutil 进行一些简单的修改以使错误消息更有帮助。我在这里提交了一个错误:https://issuetracker.google.com/issues/147020031
我正在学习GCP。我有一个名为 welynx-test1_copy 的桶 我想为其设置一个生命周期策略,以便在 23 天后删除存储桶,按照命令帮助我在 CLI 中执行了以下命令:
xenonxie@cloudshell:~ (rock-perception-263016)$ gsutil ls
gs://rock-perception-263016.appspot.com/
gs://staging.rock-perception-263016.appspot.com/
gs://welynx-test1/
gs://welynx-test1_copy/
所以你可以看到存储桶存在。
设置以下政策会出错:
xenonxie@cloudshell:~ (rock-perception-263016)$ gsutil lifecycle set {"rule": [{"action": {"type": "Delete"}, "condition": {"age": 23}}]} gs://welynx-test1_copy
CommandException: "lifecycle" command spanning providers not allowed.
我尝试遵循 help
中的语法,如下所示:
xenonxie@cloudshell:~ (rock-perception-263016)$ gsutil lifecycle --help NAME lifecycle - Get or set lifecycle configuration for a bucket
SYNOPSIS gsutil lifecycle get url gsutil lifecycle set config-json-file url...
DESCRIPTION The lifecycle command can be used to get or set lifecycle management policies for the given bucket(s). This command is supported for buckets only, not objects. For more information on object lifecycle management, please see the
Google Cloud Storage docs <https://cloud.google.com/storage/docs/lifecycle>
_.The lifecycle command has two sub-commands: GET Gets the lifecycle configuration for a given bucket. You can get the lifecycle configuration for only one bucket at a time. The output can be
redirected into a file, edited and then updated via the set sub-command.SET Sets the lifecycle configuration on one or more buckets. The config-json-file specified on the command line should be a path to a local file containing the lifecycle configuration JSON document.
EXAMPLES The following lifecycle configuration JSON document specifies that all objects in this bucket that are more than 365 days old will be deleted automatically:
{ "rule": [ { "action": {"type": "Delete"}, "condition": {"age": 365} } ] }
The following (empty) lifecycle configuration JSON document removes all lifecycle configuration for a bucket:
{}
我在这里遗漏了什么,我该如何解决?非常感谢。
你的命令的问题是你把规则放在了你想要 运行 的命令而不是配置文件中。
方法是:
- 使用生命周期配置规则创建一个 JSON 文件
- 像这样使用生命周期集
gsutil lifecycle set [CONFIG_FILE] gs://[BUCKET_NAME]
基本上,你可以像你给出的例子那样输入:
{
"rule":
[
{
"action": {"type": "Delete"},
"condition": {"age": 23}
}
]
}
并使用您创建的 JSON 文件更改 CONFIG_FILE。
显然,gsutil
检查存储桶名称是否属于 google 在 它检查生命周期文件是否存在之前:
❯ gsutil lifecycle set foo bar gs://baz
CommandException: "lifecycle" command spanning providers not allowed.
❯ gsutil lifecycle set foo gs://baz
AccessDeniedException: 403 user@domain.com does not have storage.buckets.get access to baz.
❯ gsutil lifecycle set foo gs://a-real-bucket-name
Setting lifecycle configuration on gs://a-real-bucket-name/...
ArgumentException: JSON lifecycle data could not be loaded from:
因此,如果您在第五个位置提供的不是 google 控制的桶:
gsutil lifecycle set file.json THIS_ARGUMENT
您将看到与该问题相关的错误 而不是 与该文件相关的错误。
这也让我感到困惑,我认为 google 可以对 gsutil 进行一些简单的修改以使错误消息更有帮助。我在这里提交了一个错误:https://issuetracker.google.com/issues/147020031