Skip to content

Instantly share code, notes, and snippets.

@SemantiveCode
SemantiveCode / async_invoke.py
Created October 31, 2018 10:37
Start asynchronous action Lambda
def async_invoke_handler(event, context):
   activity_task_response = states_client.get_activity_task(
       activityArn=ASYNC_ACTION_ACTIVITY_ARN,
       workerName=context.function_name,
   )
   if 'taskToken' not in activity_task_response:
       raise MissingScheduledActivityTaskException()
   input_for_nested_execution = {
@SemantiveCode
SemantiveCode / send_success.py
Created October 31, 2018 11:01
Async Execution - send success
def handler(event, context):
  task_token = event['task_token']
  output_state = event['state'][0]
  states_client.send_task_success(
      taskToken=task_token,
      output=json.dumps(output_state),
  )
  return event
@SemantiveCode
SemantiveCode / send_failure.py
Created October 31, 2018 11:02
Async Execution - send failure
def handler(event, context):
  task_token = event['task_token']
  error_info = event['error_info']
  states_client.send_task_failure(
      taskToken=task_token,
      error=error_info['Error'],
      cause=error_info.get('Cause', 'Cause is undefined.'),
  )
"""
First install text_summarizer using
pip install git+https://github.com/lambdaofgod/text-summarizer
"""
import nltk
import text_summarizer
# prepare nltk data
nltk.download('punkt')
import nltk
import gensim
text = requests.get('http://rare-technologies.com/the_matrix_synopsis.txt').text
gensim_summary = gensim.summarization.summarize(text)