我正在尝试使用 boto3 创建一个具有不同模板和类型的自动缩放组,
希望有人可以在这里帮助我:)这是我使用的代码:
import boto3
client = boto3.client('autoscaling')
def create_auto_scaling_group(**kwargs):
response = client.create_auto_scaling_group(
AutoScalingGroupName='TEST-ASG',
LaunchTemplate={
'LaunchTemplateName': 'TEST-Template',
'Version': '5'
},
MixedInstancesPolicy={
'LaunchTemplate': {
'LaunchTemplateSpecification': {
'LaunchTemplateName': 'TEST-Template',
'Version': '5'
},
'Overrides': [
{
'InstanceType': 'g4dn.xlarge',
'LaunchTemplateSpecification': {
'LaunchTemplateName': 'TEST-Template',
'Version': '5'
}
},
{
'InstanceType': 'g3s.xlarge',
'LaunchTemplateSpecification': {
'LaunchTemplateName': 'TEST-Template',
'Version': '4'
}
},
{
'InstanceType': 'p3.2xlarge',
'LaunchTemplateSpecification': {
'LaunchTemplateName': 'TEST-Template',
'Version': '6'
}
},
]
},
'InstancesDistribution': {
'OnDemandBaseCapacity': 0,
'OnDemandPercentageAboveBaseCapacity': 0,
'SpotAllocationStrategy': 'capacity-optimized',
}
},
MinSize=0,
MaxSize=0,
DesiredCapacity=0,
AvailabilityZones=[
'string',
'string',
'string',
],
Tags=[
{
'ResourceId': 'TEST-ASG',
'ResourceType': 'auto-scaling-group',
'Key': 'Name',
'Value': 'TEST-ASG',
'PropagateAtLaunch': True
},
],
)
create_auto_scaling_group()
我收到以下回复,但似乎找不到导致它的原因:
Traceback (most recent call last):
File "c:/Users/bena/PycharmProjects/pythonProject/pythonProject/New/AutoScaleOverride.py", line 69, in <module>
create_auto_scaling_group()
File "c:/Users/bena/PycharmProjects/pythonProject/pythonProject/New/AutoScaleOverride.py", line 8, in create_auto_scaling_group
response = client.create_auto_scaling_group(
File "C:\Users\bena\AppData\Local\Programs\Python\Python38\lib\site-packages\botocore\client.py", line 357, in _api_call
return self._make_api_call(operation_name, kwargs)
File "C:\Users\bena\AppData\Local\Programs\Python\Python38\lib\site-packages\botocore\client.py", line 676, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (ValidationError) when calling the CreateAutoScalingGroup operation: Valid requests must contain either LaunchTemplate, LaunchConfigurationName, InstanceId or MixedInstancesPolicy parameter.
在我尝试的单独的 aws-cli 脚本上,它工作正常,这意味着所有内容都创建时没有错误。
第一次尝试这个,所以任何帮助将不胜感激。
谢谢