本文整理匯總了Python中cfnresponse.SUCCESS屬性的典型用法代碼示例。如果您正苦於以下問題:Python cfnresponse.SUCCESS屬性的具體用法?Python cfnresponse.SUCCESS怎麽用?Python cfnresponse.SUCCESS使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類cfnresponse
的用法示例。
在下文中一共展示了cfnresponse.SUCCESS屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: handler
# 需要導入模塊: import cfnresponse [as 別名]
# 或者: from cfnresponse import SUCCESS [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)
示例2: handler
# 需要導入模塊: import cfnresponse [as 別名]
# 或者: from cfnresponse import SUCCESS [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))
示例3: handler
# 需要導入模塊: import cfnresponse [as 別名]
# 或者: from cfnresponse import SUCCESS [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))
示例4: handler
# 需要導入模塊: import cfnresponse [as 別名]
# 或者: from cfnresponse import SUCCESS [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['CidrBlocks'] = get_cidrs(
int(event['ResourceProperties']['CidrSize']),
int(event['ResourceProperties']['Qty']),
event['ResourceProperties']['VpcId']
)
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))
示例5: handler
# 需要導入模塊: import cfnresponse [as 別名]
# 或者: from cfnresponse import SUCCESS [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))
示例6: handler
# 需要導入模塊: import cfnresponse [as 別名]
# 或者: from cfnresponse import SUCCESS [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, {}, '')
示例7: handler
# 需要導入模塊: import cfnresponse [as 別名]
# 或者: from cfnresponse import SUCCESS [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))
示例8: lambda_handler
# 需要導入模塊: import cfnresponse [as 別名]
# 或者: from cfnresponse import SUCCESS [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, {}, '')
示例9: handler
# 需要導入模塊: import cfnresponse [as 別名]
# 或者: from cfnresponse import SUCCESS [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, {}, "")
示例10: handler
# 需要導入模塊: import cfnresponse [as 別名]
# 或者: from cfnresponse import SUCCESS [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)
示例11: handler
# 需要導入模塊: import cfnresponse [as 別名]
# 或者: from cfnresponse import SUCCESS [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)
示例12: handler
# 需要導入模塊: import cfnresponse [as 別名]
# 或者: from cfnresponse import SUCCESS [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)
示例13: handler
# 需要導入模塊: import cfnresponse [as 別名]
# 或者: from cfnresponse import SUCCESS [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")
示例14: handler
# 需要導入模塊: import cfnresponse [as 別名]
# 或者: from cfnresponse import SUCCESS [as 別名]
def handler(event, context):
import logging as log
import cfnresponse
log.getLogger().setLevel(log.INFO)
# This needs to change if there are to be multiple resources in the same stack
physical_id = 'TheOnlyCustomResource'
try:
log.info('Input event: %s', event)
# Check if this is a Create and we're failing Creates
if event['RequestType'] == 'Create' and event['ResourceProperties'].get('FailCreate', False):
raise RuntimeError('Create failure requested')
# Do the thing
message = event['ResourceProperties']['Message']
attributes = {
'Response': 'Hello "%s"' % message
}
cfnresponse.send(event, context, cfnresponse.SUCCESS, attributes, physical_id)
except Exception as e:
log.exception(e)
# cfnresponse's error message is always "see CloudWatch"
cfnresponse.send(event, context, cfnresponse.FAILED, {}, physical_id)
示例15: main
# 需要導入模塊: import cfnresponse [as 別名]
# 或者: from cfnresponse import SUCCESS [as 別名]
def main(event, context):
import logging as log
import cfnresponse
log.getLogger().setLevel(log.INFO)
# This needs to change if there are to be multiple resources
# in the same stack
physical_id = 'TheOnlyCustomResource'
try:
log.info('Input event: %s', event)
# Check if this is a Create and we're failing Creates
if event['RequestType'] == 'Create' and event['ResourceProperties'].get('FailCreate', False):
raise RuntimeError('Create failure requested')
# Do the thing
message = event['ResourceProperties']['Message']
attributes = {
'Response': 'You said "%s"' % message
}
cfnresponse.send(event, context, cfnresponse.SUCCESS,
attributes, physical_id)
except Exception as e:
log.exception(e)
# cfnresponse's error message is always "see CloudWatch"
cfnresponse.send(event, context, cfnresponse.FAILED, {}, physical_id)