【问题标题】:How to change the EC2 instance types in a Elastic Beanstalk environment programmatically?如何以编程方式更改 Elastic Beanstalk 环境中的 EC2 实例类型?
【发布时间】:2020-12-10 14:22:15
【问题描述】:

我想使用boto3 更改 Elastic Beanstalk 环境中的 EC2 实例类型。

但是,我找不到执行此操作的正确函数。

update_environment 似乎不提供更改 EC2 实例类型的功能。

所有update_* 函数似乎都没有提供此功能。

我的Environment typeLoad balanced,我使用Combine purchase options and instances 代替Fleet composition

有人知道如何更改弹性豆茎使用的实例类型吗?

【问题讨论】:

    标签: python amazon-web-services amazon-elastic-beanstalk boto3


    【解决方案1】:

    您可以使用update_environment 更新实例类型。

    已验证示例(即我在自己的 EB 环境中使用它):

    import boto3
    
    eb = boto3.client('elasticbeanstalk')
    
    response = eb.update_environment(
        ApplicationName='<your-eb-app-name>',
        EnvironmentName='<your-eb-env-name>',
        OptionSettings=[
            {
                'Namespace': 'aws:autoscaling:launchconfiguration',
                'OptionName': 'InstanceType',
                'Value': 't2.small'
            },
        ]
    )
    
    print(response)
    

    现场更新

    EB 环境的现场设置使用aws:ec2:instances 设置。

    response = eb.update_environment(
        ApplicationName='<your-eb-app-name>',
        EnvironmentName='<your-eb-env-name>',
        OptionSettings=[
            {
                'Namespace': 'aws:ec2:instances',
                'OptionName': 'EnableSpot',
                'Value': 'true'
            },
            {
                'Namespace': 'aws:ec2:instances',
                'OptionName': 'InstanceTypes',
                'Value': 't2.large,t3.large'
            }      
        ]
    )
    

    还有更多选项需要设置,具体取决于您的具体要求。

    【讨论】:

    • 我的 InstanceTypes 最初是 t2a.medium, t3a.medium。在应用您的OptionSettingsValue 等于t2.large, t3.large 后,它会更改为t2.large, t3a.large, t3a.medium。这太奇怪了。
    • 我使用eb config get &lt;my_configuration_name&gt;获取配置文件。
    • 我不想使用*.medium 实例类型。
    • 我必须指定至少 2 种实例类型,因为我使用的是 Spot 实例。
    • @Brian 嗨。我用现场特定设置更新了答案。你的问题没有提到点,因此一开始我只包括了最常用的实例类型设置。
    猜你喜欢
    • 2020-10-23
    • 2017-12-16
    • 2016-07-13
    • 2018-09-24
    • 2021-04-16
    • 2015-07-04
    • 1970-01-01
    • 2017-06-16
    • 2015-12-21
    相关资源
    最近更新 更多