in lambda/source/invoke_state_machine.py [0:0]
def lambda_handler(event, context):
if event['RequestType'] == 'Delete':
try:
responseData = {}
send_cfnresponse(event, context, SUCCESS, responseData)
except Exception as inst:
print(inst)
send_cfnresponse(event, context, FAILED, {})
elif event['RequestType'] == 'Create':
try:
smArn = event['ResourceProperties']['StateMachineArn']
addOnS3Bucket = event['ResourceProperties']['AddOnS3Bucket']
productName = event['ResourceProperties']['ProductName']
productTemplateS3Url = event['ResourceProperties']['ProductS3Url']
smInputJSON = create_state_machine_input(addOnS3Bucket, productName, productTemplateS3Url)
# Print inputs from event
print('State machine ARN: ', smArn)
print('S3 Bucket to upload addon files: ', addOnS3Bucket)
print('Product name: ', productName)
print('Product Cloudformation template S3 URL: ', productTemplateS3Url)
print('State machine input JSON: ', smInputJSON)
# Start state machine execution
smExecutionArn = invoke(smArn, smInputJSON)
# Wait for state machine execution to complete. Approx. it takes 35 seconds.
# TODO - This is not ideal to wait in lambda function. Need refactor.
time.sleep(45)
# Get state machine execution result
smExecutionOutput = get_output(smExecutionArn)
send_cfnresponse(event, context, SUCCESS, {})
except Exception as ex:
print('Error!')
print(ex)
send_cfnresponse(event, context, FAILED, {})