Lambda:创建Lambda函数来启动EC2/Join ELB

2024-10-04 15:30:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经通过python2.7(使用boto3)编写了一个Lambda函数来启动EC2实例,然后将EC2实例连接到一个固定ELB(用于简单的故障转移)。在

当lambda关闭时,它启动EC2,但不将EC2连接到ELB。在

指导?在

  1. 如何对InstanceID和ELBID/
  2. 为什么不起作用?在

    #!/usr/bin/env python
    import boto3
    
    #True - Do nothing False - screw it all up
    debugMode = False
    
    #Declare
    
    
    #Instance Status
    #Hard Code InstanceIDs to script
    if debugMode == False:
        def lambda_handler(event, context):
    client = boto3.client('ec2')
    response = client.start_instances(InstanceIds=['i-someid',],
                       DryRun=False)
    print ('[SPACE]:')
    
    #Attach Instances to ELB once started.
    #Hardcode Instance
    def lamdba_hander(event, context):
    client = boto3.client('elb')
    response = client.register_instances_with_load_balancer(LoadBalancerName='someelb', Instances=[{'InstanceID': 'i-someid'},])
    print('[SPACE]:')
    

Tags: to实例instancelambdaclienteventfalseresponse

热门问题