黄立 2018-06-04
使用lambda定时启动一个EC2。
""" Lambda to launch ec2-instances """ import boto3 REGION = 'cn-north-1' # region to launch instance. EC2 = boto3.client('ec2', region_name=REGION) def lambda_to_ec2(event, context): """ Lambda handler taking [message] and creating a httpd instance with an echo. """ message = event['message'] instance = EC2.run_instances( ImageId='ami-c333edae', InstanceType='t2.medium', MinCount=1, MaxCount=1, SecurityGroups='prod-rds-backup', SubnetId='subnet-d45208b1', PrivateIpAddress='10.184.12.240', InstanceInitiatedShutdownBehavior='stop' ) print "New instance created." instance_id = instance['Instances'][0]['InstanceId'] print instance_id return instance_id
创建Lambda函数
创建Cloudwatch event
创建trigger
f = lambda x, y, z: x + y + z # returns a function that can optionally be assigned a name. def func: