【问题标题】:How to delete an autoscaling group and launch configuration or launch template?如何删除自动伸缩组并启动配置或启动模板?
【发布时间】:2019-07-31 09:17:11
【问题描述】:

Auto Scaling 组可以与启动配置 (LC) 或启动模板 (LT) 相关联。我正在尝试删除自动缩放组及其关联的 LC 或 LT。有没有简单的方法可以做到这一点?

使用aws autoscaling delete-auto-scaling-group (delete-auto-scaling-group) 时似乎没有自动删除 LC/LT 的选项。

因此,我似乎需要使用aws ec2 delete-launch-template (delete-launch-template) 和/或aws autoscaling delete-launch-configuration (delete-launch-configuration)。

如果我有一个自动缩放组名称,我如何获得关联的 LC/LT?

【问题讨论】:

  • 这似乎不是与编程相关的问题,因此对于 SO 来说是题外话。也就是说,与 CLI 中的大多数内容一样,there is a describe command for ASGs 返回一个 LaunchConfigurationName 字段。

标签: amazon-web-services amazon-ec2 aws-cli


【解决方案1】:

看来这只能通过脚本来完成。这是我所做的:

#! /bin/bash

set -ex

# get launch configuration name or launch template id
my_lc=$(aws autoscaling describe-auto-scaling-groups --no-paginate --output text --query AutoScalingGroups[?AutoScalingGroupName==\'${MY_ASG_NAME}\'].LaunchConfigurationName)

my_lt=$(aws autoscaling describe-auto-scaling-groups --no-paginate --output text --query AutoScalingGroups[?AutoScalingGroupName==\'${MY_ASG_NAME}\'].LaunchTemplate.LaunchTemplateId)

# delete ASG
aws autoscaling delete-auto-scaling-group --auto-scaling-group-name ${MY_ASG_NAME} --force-delete

# delete launch configs if they exist
aws autoscaling delete-launch-configuration --launch-configuration-name ${my_lc} || true # Don't exit script if command fails

# delete launch templates if they exist
aws ec2 delete-launch-template --launch-template-name ${my_lt} || true # Don't exit script if command fails

【讨论】:

    猜你喜欢
    • 2021-07-16
    • 1970-01-01
    • 2011-08-16
    • 2018-01-29
    • 2021-09-13
    • 2019-02-27
    • 2020-09-10
    • 2018-12-23
    • 2020-03-18
    相关资源
    最近更新 更多