How do I invoke another lambda async and pass context to it

0 votes

I'm trying to work out two basic lambdas using Python2.7 runtime for SQS message processing. 

One lambda reads from SQS invokes and passes data to another lambda via context. I can invoke the other lambda but the user context is empty in it. This is the code of SQS reader lambda I wrote:

import boto3
import base64
import json
import logging

messageDict = {'queue_url': 'queue_url',
       'receipt_handle': 'receipt_handle',
       'body': 'messageBody'}
ctx = {
   'custom': messageDict,
   'client': 'SQS_READER_LAMBDA',
   'env': {'test': 'test'},
}

payload = json.dumps(ctx)
payloadBase64 = base64.b64encode(payload)

client = boto3.client('lambda')
client.invoke(
    FunctionName='LambdaWorker',
    InvocationType='Event',
    LogType='None',
    ClientContext=payloadBase64,
    Payload=payload
)
And this is how I'm trying to inspect and print the contents of context variable inside invoked lambda, so I could check logs in CloudWatch:

memberList = inspect.getmembers(context)
    for a in memberList:

       logging.error(a)


 

Nothing is working here  and CloudWatch shows user context is empty:

('client_context', None)

I took reference from this as well:  https://github.com/aws/aws-sdk-js/issues/1388 but still now working

Help!!!!

Apr 27, 2018 in AWS by Flying geek
• 3,280 points

edited Apr 27, 2018 by Flying geek 6,290 views

1 answer to this question.

0 votes

I tried several times trying to pass the data through the context then I gave up on it.
However, I was able to pass the data through the Payload param:

client.invoke(
    FunctionName='LambdaWorker',
    InvocationType='Event',
    LogType='None',
    Payload=json.dumps(payload)
)

And then to read it from event parameter inside invoked lambda:

ctx = json.dumps(event)
answered Apr 27, 2018 by Cloud gunner
• 4,670 points

Related Questions In AWS

0 votes
0 answers
+2 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 58,100 points
2,658 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
3,952 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP