AWS lambda应用
程序员文章站
2022-04-17 23:19:22
...
使用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
上一篇: Lambda表达式的引入
下一篇: Backbone和ReactJS的整合