當前位置: 首頁>>代碼示例>>Python>>正文


Python cfnresponse.send方法代碼示例

本文整理匯總了Python中cfnresponse.send方法的典型用法代碼示例。如果您正苦於以下問題:Python cfnresponse.send方法的具體用法?Python cfnresponse.send怎麽用?Python cfnresponse.send使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cfnresponse的用法示例。


在下文中一共展示了cfnresponse.send方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: handler

# 需要導入模塊: import cfnresponse [as 別名]
# 或者: from cfnresponse import send [as 別名]
def handler(event, context):
    timer = threading.Timer((context.get_remaining_time_in_millis() / 1000.00) - 0.5, timeout, args=[event, context])
    timer.start()
    print('Received event: %s' % json.dumps(event))
    status = cfnresponse.SUCCESS
    reason = None
    physical_id = None
    try:
        service_name = event['ResourceProperties']['ServiceName']
        if 'CustomSuffix' in event['ResourceProperties'].keys():
            custom_suffix = event['ResourceProperties']['CustomSuffix']
        else:
            custom_suffix = None
        if event['RequestType'] != 'Delete':
            physical_id = create_role(service_name, custom_suffix)
        else:
            physical_id = event['PhysicalResourceId']
            delete_role(physical_id)
    except Exception as e:
        logging.error('Exception: %s' % e, exc_info=True)
        status = cfnresponse.FAILED
        reason = str(e)
    finally:
        timer.cancel()
        cfnresponse.send(event, context, status, {'Arn': physical_id}, physical_id, reason) 
開發者ID:awslabs,項目名稱:aws-servicebroker,代碼行數:27,代碼來源:lambda_function.py

示例2: handler

# 需要導入模塊: import cfnresponse [as 別名]
# 或者: from cfnresponse import send [as 別名]
def handler(event, context):
    response_code = cfnresponse.SUCCESS
    response_data = {}
    print(event)
    if event['RequestType'] == 'Create':
        phys_id = ''.join(random.choice(alnum) for _ in range(16))
    else:
        phys_id = event['PhysicalResourceId']
    try:
        if event['RequestType'] in ['Create', 'Update']:
            if 'Length' in event['ResourceProperties']:
                pw_len = int(event['ResourceProperties']['Length'])
            else:
                pw_len = 16
            response_data['EMRClusterName'] = generate_password(pw_len)
        cfnresponse.send(event, context, response_code, response_data, phys_id)
    except Exception as e:
        print(str(e))
        traceback.print_exc()
        cfnresponse.send(event, context, cfnresponse.FAILED, response_data, phys_id, str(e)) 
開發者ID:awslabs,項目名稱:aws-servicebroker,代碼行數:22,代碼來源:lambda_function.py

示例3: handler

# 需要導入模塊: import cfnresponse [as 別名]
# 或者: from cfnresponse import send [as 別名]
def handler(event, context):
    response_code = cfnresponse.SUCCESS
    response_data = {}
    print(event)
    if event['RequestType'] == 'Create':
        phys_id = ''.join(random.choice(alnum) for _ in range(16))
    else:
        phys_id = event['PhysicalResourceId']
    try:
        if event['RequestType'] in ['Create', 'Update']:
            response_data['AvailabilityZones'] = get_azs(int(event['ResourceProperties']['Qty']))
        cfnresponse.send(event, context, response_code, response_data, phys_id)
    except Exception as e:
        print(str(e))
        traceback.print_exc()
        cfnresponse.send(event, context, cfnresponse.FAILED, response_data, phys_id, str(e)) 
開發者ID:awslabs,項目名稱:aws-servicebroker,代碼行數:18,代碼來源:lambda_function.py

示例4: handler

# 需要導入模塊: import cfnresponse [as 別名]
# 或者: from cfnresponse import send [as 別名]
def handler(event, context):
    response_code = cfnresponse.SUCCESS
    response_data = {}
    print(event)
    if event['RequestType'] == 'Create':
        phys_id = ''.join(random.choice(alnum) for _ in range(16))
    else:
        phys_id = event['PhysicalResourceId']
    try:
        if event['RequestType'] in ['Create', 'Update']:
            if 'Length' in event['ResourceProperties']:
                pw_len = int(event['ResourceProperties']['Length'])
            else:
                pw_len = 16
            response_data['DBName'] = generate_password(pw_len)
        cfnresponse.send(event, context, response_code, response_data, phys_id)
    except Exception as e:
        print(str(e))
        traceback.print_exc()
        cfnresponse.send(event, context, cfnresponse.FAILED, response_data, phys_id, str(e)) 
開發者ID:awslabs,項目名稱:aws-servicebroker,代碼行數:22,代碼來源:lambda_function.py

示例5: handler

# 需要導入模塊: import cfnresponse [as 別名]
# 或者: from cfnresponse import send [as 別名]
def handler(event, context):
    response_code = cfnresponse.SUCCESS
    response_data = {}
    print(event)
    if event['RequestType'] == 'Create':
        phys_id = ''.join(random.choice(alnum) for _ in range(16))
    else:
        phys_id = event['PhysicalResourceId']
    try:
        if event['RequestType'] in ['Create', 'Update']:
            response_data['EMRCidr'] = get_cidrs(
                int(event['ResourceProperties']['CidrSize']),
                int(event['ResourceProperties']['Qty']),
                event['ResourceProperties']['VpcId']
            )[0]
        cfnresponse.send(event, context, response_code, response_data, phys_id)
    except Exception as e:
        print(str(e))
        traceback.print_exc()
        cfnresponse.send(event, context, cfnresponse.FAILED, response_data, phys_id, str(e)) 
開發者ID:awslabs,項目名稱:aws-servicebroker,代碼行數:22,代碼來源:lambda_function.py

示例6: handler

# 需要導入模塊: import cfnresponse [as 別名]
# 或者: from cfnresponse import send [as 別名]
def handler(event, context):
    response_code = cfnresponse.SUCCESS
    response_data = {}
    print(event)
    if event['RequestType'] == 'Create':
        phys_id = ''.join(random.choice(alnum) for _ in range(16))
    else:
        phys_id = event['PhysicalResourceId']
    try:
        if event['RequestType'] in ['Create', 'Update']:
            if 'Length' in event['ResourceProperties']:
                pw_len = int(event['ResourceProperties']['Length'])
            else:
                pw_len = 16
            response_data['MasterUserPassword'] = generate_password(pw_len)
        cfnresponse.send(event, context, response_code, response_data, phys_id)
    except Exception as e:
        print(str(e))
        traceback.print_exc()
        cfnresponse.send(event, context, cfnresponse.FAILED, response_data, phys_id, str(e)) 
開發者ID:awslabs,項目名稱:aws-servicebroker,代碼行數:22,代碼來源:lambda_function.py

示例7: handler

# 需要導入模塊: import cfnresponse [as 別名]
# 或者: from cfnresponse import send [as 別名]
def handler(event, context):
    try:
        if event['RequestType'] == 'Create':
            # Test Integration
            print 'Getting all pets'
            response = requests.get(event['ResourceProperties']['IntegrationEndpoint'])
            print "Status code: " + str(response.status_code)
            if response.status_code != 200:
                raise Exception('Error: Status code received is not 200')
        elif event['RequestType'] == 'Update':
            pass
        elif event['RequestType'] == 'Delete':
            pass
        cfnresponse.send(event, context, cfnresponse.SUCCESS, {}, '')
    except:
        print traceback.print_exc()
        cfnresponse.send(event, context, cfnresponse.FAILED, {}, '') 
開發者ID:aws-quickstart,項目名稱:connect-integration-examples,代碼行數:19,代碼來源:main.py

示例8: handler

# 需要導入模塊: import cfnresponse [as 別名]
# 或者: from cfnresponse import send [as 別名]
def handler(event, context):
    print("Received request:", json.dumps(event, indent=4))

    action = event["RequestType"]

    stack = event["ResourceProperties"]["StackName"]
    resources = int(event["ResourceProperties"]["ResourceCount"])

    try:
        log(stack, action, 1)

        if action == "Create":
            log(stack, "ResourceCount", resources)

        cfnresponse.send(event, context, cfnresponse.SUCCESS, {}, "{} metrics".format(stack))
    except Exception as e:
        cfnresponse.send(event, context, cfnresponse.FAILED, {
            "Data": str(e),
        }, "{} metrics".format(stack)) 
開發者ID:awslabs,項目名稱:aws-cloudformation-templates,代碼行數:21,代碼來源:resource.py

示例9: lambda_handler

# 需要導入模塊: import cfnresponse [as 別名]
# 或者: from cfnresponse import send [as 別名]
def lambda_handler(event, context):
    try:
        print(json.dumps(event))
        print(event['RequestType'])
        print('Getting AnsibleConfigServer instance...')
        print event["ResourceProperties"]["StackName"]
        print event["ResourceProperties"]["AnsibleConfigServer"]
        if event['RequestType'] == 'Delete':
            print("Run unsubscribe script")
            ssm = boto3.client('ssm')
            instanceID = event["ResourceProperties"]["AnsibleConfigServer"]
            response = ssm.send_command(Targets=[{"Key":"instanceids","Values":[instanceID]}],
                            DocumentName="AWS-RunShellScript",
                            Parameters={"commands":["python unsubscribe.py %s" %(event["ResourceProperties"]["StackName"])],
                                        "executionTimeout":["600"],
                                        "workingDirectory":["/root"]},
                            Comment="Execute script in ansible server to unsubscribe nodes from RH subscription",
                            TimeoutSeconds=120)
            print(response)                   
    except Exception as e:
        print(e)
        traceback.print_exc()
    cfnresponse.send(event, context, cfnresponse.SUCCESS, {}, '') 
開發者ID:aws-quickstart,項目名稱:quickstart-redhat-openshift,代碼行數:25,代碼來源:lambda_function.py

示例10: handler

# 需要導入模塊: import cfnresponse [as 別名]
# 或者: from cfnresponse import send [as 別名]
def handler(event, context):
    print(event)
    try:
        resource_properties = event['ResourceProperties']
        request_type = event['RequestType']
        if request_type in ['Create', 'Update']:
            update_parameters = {key: cast_type(resource_properties[key]) for key, cast_type in
                                 password_policy_keys.items()}
            print(update_parameters)
            response = iam.update_account_password_policy(**update_parameters)
            print(response)
        elif request_type is 'Delete':
            iam.delete_account_password_policy()

        cfnresponse.send(event, context, cfnresponse.SUCCESS, {}, "")
    except Exception as e:
        print(e)
        cfnresponse.send(event, context, cfnresponse.FAILED, {}, "") 
開發者ID:theserverlessway,項目名稱:aws-baseline,代碼行數:20,代碼來源:password-policy.py

示例11: timeout

# 需要導入模塊: import cfnresponse [as 別名]
# 或者: from cfnresponse import send [as 別名]
def timeout(event, context):
    logging.error('Execution is about to time out, sending failure response to CloudFormation')
    cfnresponse.send(event, context, cfnresponse.FAILED, {}, None) 
開發者ID:awslabs,項目名稱:aws-servicebroker,代碼行數:5,代碼來源:lambda_function.py

示例12: handler

# 需要導入模塊: import cfnresponse [as 別名]
# 或者: from cfnresponse import send [as 別名]
def handler(event, context):
    timer = threading.Timer((context.get_remaining_time_in_millis() / 1000.00) - 0.5, timeout, args=[event, context])
    timer.start()
    print('Received event: %s' % json.dumps(event))
    status = cfnresponse.SUCCESS
    reason = None
    physical_id = None
    try:
        data = s3_client.get_object(Bucket=event['ResourceProperties']['Bucket'],
                                    Key=event['ResourceProperties']['Key'])['Body'].read()
        try:
            bot = json.loads(data)
        except Exception as e:
            logging.error('Exception: %s' % e, exc_info=True)
            raise Exception('Intent json is malformed')
        if event['RequestType'] != 'Delete':
            create_bot(bot)
            physical_id = bot['name']
        else:
            delete_bot(event['PhysicalResourceId'])
    except Exception as e:
        logging.error('Exception: %s' % e, exc_info=True)
        status = cfnresponse.FAILED
        reason = str(e)
    finally:
        timer.cancel()
        cfnresponse.send(event, context, status, {}, physical_id, reason) 
開發者ID:awslabs,項目名稱:aws-servicebroker,代碼行數:29,代碼來源:lambda_function.py

示例13: handler

# 需要導入模塊: import cfnresponse [as 別名]
# 或者: from cfnresponse import send [as 別名]
def handler(event, context):
    timer = threading.Timer((context.get_remaining_time_in_millis() / 1000.00) - 0.5, timeout, args=[event, context])
    timer.start()
    print('Received event: %s' % json.dumps(event))
    status = cfnresponse.SUCCESS
    reason = None
    physical_id = None
    try:
        if event['RequestType'] != 'Delete':
            data = s3_client.get_object(Bucket=event['ResourceProperties']['Bucket'],
                                        Key=event['ResourceProperties']['Key'])['Body'].read()
            try:
                slots = json.loads(data)
            except Exception as e:
                logging.error('Exception: %s' % e, exc_info=True)
                raise Exception('Intent json is malformed')
            if type(slots) != list:
                raise Exception('JSON must be a list of one of more Slots')
            for s in slots:
                create_custom_slot_type(s)
            physical_id = ','.join([s['name'] for i in slots])
        else:
            for s in event['PhysicalResourceId'].split(','):
                delete_custom_slot_type(s)

    except Exception as e:
        logging.error('Exception: %s' % e, exc_info=True)
        status = cfnresponse.FAILED
        reason = str(e)
    finally:
        timer.cancel()
        cfnresponse.send(event, context, status, {}, physical_id, reason) 
開發者ID:awslabs,項目名稱:aws-servicebroker,代碼行數:34,代碼來源:lambda_function.py

示例14: handler

# 需要導入模塊: import cfnresponse [as 別名]
# 或者: from cfnresponse import send [as 別名]
def handler(event, context):
    timer = threading.Timer((context.get_remaining_time_in_millis() / 1000.00) - 0.5, timeout, args=[event, context])
    timer.start()
    print('Received event: %s' % json.dumps(event))
    status = cfnresponse.SUCCESS
    reason = None
    physical_id = None
    try:
        if event['RequestType'] != 'Delete':
            data = s3_client.get_object(Bucket=event['ResourceProperties']['Bucket'],
                                        Key=event['ResourceProperties']['Key'])['Body'].read()
            try:
                intents = json.loads(data)
            except Exception as e:
                logging.error('Exception: %s' % e, exc_info=True)
                raise Exception('Intent json is malformed')
            if type(intents) != list:
                raise Exception('JSON must be a list of one of more Intents')
            for i in intents:
                    create_intent(i)
            physical_id = ','.join([i['name'] for i in intents])
        else:
            for i in event['PhysicalResourceId'].split(','):
                delete_intent(i)
    except Exception as e:
        logging.error('Exception: %s' % e, exc_info=True)
        status = cfnresponse.FAILED
        reason = str(e)
    finally:
        timer.cancel()
        cfnresponse.send(event, context, status, {}, physical_id, reason) 
開發者ID:awslabs,項目名稱:aws-servicebroker,代碼行數:33,代碼來源:lambda_function.py

示例15: handler

# 需要導入模塊: import cfnresponse [as 別名]
# 或者: from cfnresponse import send [as 別名]
def handler(event, context):
    print(event)
    response_data = {}
    response_data['Data'] = 'DataResponse'
    response_data['Reason'] = 'SomeTestReason'
    cfnresponse.send(event, context, cfnresponse.SUCCESS, response_data, "CustomResourcePhysicalID") 
開發者ID:theserverlessway,項目名稱:formica,代碼行數:8,代碼來源:resource.py


注:本文中的cfnresponse.send方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。