我需要创建一个 AWS firehose 流,所以我编写了以下代码:
def create_kinesis_firehose_stream(firehoseStreamName, roleARN, bucketARN, prefix, sizeInMBs, intervalInSeconds):
createdFirehose = None
try:
createdFirehose = firehoseAWS.create_delivery_stream(
DeliveryStreamName = firehoseStreamName,
S3DestinationConfiguration = {
'RoleARN': roleARN,
'BucketARN': bucketARN,
'Prefix': prefix,
'BufferingHints': {
'SizeInMBs': sizeInMBs,
'IntervalInSeconds': intervalInSeconds
}
})
except Exception as E:
print (E)
return {'isValid': False }
httpStatusCode = createdFirehose['ResponseMetadata']['HTTPStatusCode']
if httpStatusCode != 200:
raise Exception('firehoseAWS.create_delivery_stream function returned http code: ' + httpStatusCode)
return {'isValid': False}
firehoseStatus = None
firehoseOnCreationResponse = None
while firehoseStatus != 'ACTIVE':
time.sleep(5) **** is this the proper way ? ****
try:
firehoseOnCreationResponse = firehoseAWS.describe_delivery_stream(DeliveryStreamName = firehoseStreamName)
if firehoseOnCreationResponse['DeliveryStreamDescription'] != None:
if firehoseOnCreationResponse['DeliveryStreamDescription']['DeliveryStreamStatus'] != None:
firehoseStatus = firehoseOnCreationResponse['DeliveryStreamDescription']['DeliveryStreamStatus']
print ('Waiting for the new ' + firehoseStreamName + ' Firehose to be created.')
except Exception as E:
print(E)
return {'isValid': False}
# Log:
print('Succeed to create new Kinesis Firehose Stream, Stream Name: ' + firehoseStreamName)
return { 'isValid': firehoseOnCreationResponse['ResponseMetadata']['HTTPStatusCode'] == 200 }
我在这个函数中所做的是创建了firehose,然后,我使用describe_delivery_stream
函数来检索我创建的firehose,看看它是否真的被创建了。
发生的事情是这样的,当create_delivery_stream
被调用时,创建 firehose 流并将其移动到“活动”状态大约需要一分钟,所以我添加了 5 秒的睡眠来调用,describe_delivery_stream
直到 firehose 被正确创建。
在这种情况下,这似乎sleep
会损坏我的代码并且格式不正确。
我需要知道是否有另一种方法来检查我的消防软管是否正确创建?