以编程方式使用 AWS CLI 确定是否删除了 Amazon Redshift 集群

Programmatically using the AWS CLI to determine whether an Amazon Redshift cluster is deleted

正如标题所说,想知道 Redshift 集群何时被删除。我在 CI/CD 中使用它,之前的命令是删除集群,我想在此检查后自动执行更多功能。

目前的想法是使用 describe-cluster 端点并检查 ClusterNotFound 是否在字符串中。来自已删除集群的示例响应:

An error occurred (ClusterNotFound) when calling the DescribeClusters operation: Cluster <name> not found.

我会使用 describe-clusters 并检查输出以确保所需的集群不存在。

您可以结合使用 AWS CLI and jq:

if [[ $(aws redshift describe-clusters | jq '[.Clusters[].ClusterIdentifier] | any(contains("<name>"))') == "true" ]]; then exit 1; fi