AWS boto3 - 如何运行现货实例?

Zug*_*dud 0 amazon-ec2 amazon-web-services boto3 aws-lambda

我目前这样做是为了从 lambda 函数启动 EC2 按需实例:

 ec2 = boto3.resource('ec2', region_name='us-east-2')

 instances = ec2.create_instances(
    ImageId='ami-0c709cc4edbf9a8c0', 
    MinCount=1, 
    MaxCount=1,
    KeyName="mykey",
    InstanceType="m4.large",
    IamInstanceProfile={'Arn': 'arn:aws:iam::231412431243:instance-profile/myimage'},
    UserData=user_data_script
Run Code Online (Sandbox Code Playgroud)

我可以在此处添加一个属性来将其作为现货实例运行吗?

Joh*_*ein 6

create_instances()对于竞价实例,命令中有一个参数:

    InstanceMarketOptions={
        'MarketType': 'spot',
        'SpotOptions': {
            'MaxPrice': 'string',
            'SpotInstanceType': 'one-time'|'persistent',
            'BlockDurationMinutes': 123,
            'ValidUntil': datetime(2015, 1, 1),
            'InstanceInterruptionBehavior': 'hibernate'|'stop'|'terminate'
        }
    },
Run Code Online (Sandbox Code Playgroud)