in source/StartPublicationFunction/app.py [0:0]
def lambda_handler(event, context):
try:
global log_level
log_level = str(os.environ.get('LOG_LEVEL')).upper()
if log_level not in [
'DEBUG', 'INFO',
'WARNING', 'ERROR',
'CRITICAL'
]:
log_level = 'ERROR'
logging.getLogger().setLevel(log_level)
STATE_MACHINE_ARN = os.environ['STATE_MACHINE_ARN']
logging.debug('event={}'.format(event))
bucket = event['Records'][0]['s3']['bucket']['name']
key = event['Records'][0]['s3']['object']['key']
EXECUTION_NAME = 'Ex@{}'.format(str(calendar.timegm(time.gmtime())))
INPUT = json.dumps({
"Bucket" : bucket,
"Key" : key
})
sfn = boto3.client('stepfunctions')
logging.debug('EXECUTION_NAME={}'.format(EXECUTION_NAME))
response = sfn.start_execution(
stateMachineArn=STATE_MACHINE_ARN,
name=EXECUTION_NAME,
input=INPUT
)
logging.debug('INPUT={}'.format(INPUT))
logging.debug('sf response={}'.format(response))
except Exception as error:
logging.error('lambda_handler error: %s' % (error))
logging.error('lambda_handler trace: %s' % traceback.format_exc())
result = {
'Error': 'error={}'.format(error)
}
return json.dumps(result)
return {
"Message": "State machine started"
}