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,150 points

edited Apr 27, 2018 by Flying geek 1,383 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,260 points

Related Questions In AWS

0 votes
1 answer

How do I roll-back a message to Amazon MQ (AMQ) from Lambda?

It is apparently not possible using STOMP ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 56,520 points
130 views
0 votes
1 answer

How do I add python libraries to an AWS lambda function for Alexa?

As it is described in the Amazon ...READ MORE

answered Oct 23, 2018 in AWS by Archana
• 4,090 points
239 views
0 votes
1 answer

How do I write an S3 Object to a file?

While IOUtils.copy() and IOUtils.copyLarge() are great, I would prefer the old ...READ MORE

answered Jul 13, 2018 in AWS by Hammer
• 360 points
88 views
0 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
• 56,520 points
131 views
+13 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 26, 2018 in DevOps & Agile by DragonLord999
• 8,380 points
112 views
0 votes
1 answer