aysh
aysh

Reputation: 599

How to call event parameter to another function

My lambda handler is below

def lambda_handler(event, context):
    
    if event['params']['path'] == 'INSERT':
        return (test())

    else:
        return (test1())

I need to use the INSERT variable into inside another, here test. if else need to add to another function which test1

def test():
     return 'hi'

def test1():
    event['params']['path'] == 'MODIFY':
    return 'hello'

Upvotes: 0

Views: 291

Answers (1)

Banana
Banana

Reputation: 2524

from @Andrew Li's comment:

def lambda_handler(event, context):
    
    if event['params']['path'] == 'INSERT':
        return (test())

    else:
        return (test1(event['params']['path']))

def test1(insert_var):
    if insert_var == 'MODIFY':
        return 'hello'

But this could be made easier with a switch-like statement using a dictionary:

to_return = {'INSERT':'hi', 'MODIFY':'hello'}
def lambda_handler(event, context):
    # return None by default
    return to_return.get(event['params']['path'], None)

Upvotes: 1

Related Questions