`
eye-lij
  • 浏览: 3323 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

AWS lambda应用

阅读更多

使用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

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics