Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 Lambda脚本更新以更改实例大小_Python 2.7_Aws Lambda_Amazon Iam - Fatal编程技术网

Python 2.7 Lambda脚本更新以更改实例大小

Python 2.7 Lambda脚本更新以更改实例大小,python-2.7,aws-lambda,amazon-iam,Python 2.7,Aws Lambda,Amazon Iam,我想更新此脚本以停止此实例,进行备份,更改大小,然后重新启动该实例 基本上,我正在尝试将三个脚本组合在一起。所有人都说它们是用Python2.7编写的,但语法不匹配 请参阅下面的脚本。我真的可以把这些脚本混在一起吗?第一个脚本看起来像是我会这样做: def lambda_handler(event, context): ec2 = boto3.client('ec2', region_name=region) ec2.change_instances(Instanc

我想更新此脚本以停止此实例,进行备份,更改大小,然后重新启动该实例

基本上,我正在尝试将三个脚本组合在一起。所有人都说它们是用Python2.7编写的,但语法不匹配

请参阅下面的脚本。我真的可以把这些脚本混在一起吗?第一个脚本看起来像是我会这样做:

     def lambda_handler(event, context):
     ec2 = boto3.client('ec2', region_name=region)
     ec2.change_instances(InstanceIds=instances)
     print 'started your instances: ' + str(instances)
但我甚至不确定这是不是正确的语法。在第二个脚本中说:

    client.modify_instance_attribute(InstanceId=my_instance, 
    Attribute='instanceType', Value='m3.xlarge')
显然,我会更改变量,但不确定是否需要def lamba_处理程序语法

你能给我指一下正确的方向吗

脚本1 脚本2 进口boto3 地区='us-east-1' 实例=['XXXXXXXXXXXXXX']

def lambda_handler(event, context):
    ec2 = boto3.client('ec2', region_name=region)
    ec2.stop_instances(InstanceIds=instances)
    print 'started your instances: ' + str(instances)
    waiter=ec2.get_waiter('instance_stopped')
    waiter.wait(InstanceIds=[my_instance])

# Change the instance type
    ec2.modify_instance_attribute(InstanceId=my_instance, 
Attribute='instanceType', Value='m3.xlarge')

    ec2.start_instances(InstanceIds=instances)
    print 'started your instances: ' + str(instances)
进口boto3 地区='us-east-1' 实例=['XXXXXXXXXXXXXX']

def lambda_handler(event, context):
    ec2 = boto3.client('ec2', region_name=region)
    ec2.stop_instances(InstanceIds=instances)
    print 'started your instances: ' + str(instances)
    waiter=ec2.get_waiter('instance_stopped')
    waiter.wait(InstanceIds=[my_instance])

# Change the instance type
    ec2.modify_instance_attribute(InstanceId=my_instance, 
Attribute='instanceType', Value='m3.xlarge')

    ec2.start_instances(InstanceIds=instances)
    print 'started your instances: ' + str(instances)

脚本2看起来非常好(除了混合使用的
实例
我的实例
。您的问题是不知道如何将其用作Lambda函数吗?Lambda函数如何知道要更改哪个实例?(即,如何将ID传递给函数?)脚本2看起来非常好(除了混合使用的
实例
my_实例
。您的问题是不知道如何将其用作Lambda函数吗?Lambda函数如何知道要更改哪个实例?(即,如何将ID传递给函数?)
def lambda_handler(event, context):
    ec2 = boto3.client('ec2', region_name=region)
    ec2.stop_instances(InstanceIds=instances)
    print 'started your instances: ' + str(instances)
    waiter=ec2.get_waiter('instance_stopped')
    waiter.wait(InstanceIds=[my_instance])

# Change the instance type
    ec2.modify_instance_attribute(InstanceId=my_instance, 
Attribute='instanceType', Value='m3.xlarge')

    ec2.start_instances(InstanceIds=instances)
    print 'started your instances: ' + str(instances)