-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support one Local Lambda calling another Local Lambda scenarios #510
Comments
Actually, this exact scenario is being enabled by #508. More details on this soon, but the tl;dr version is, we will provide a new command (possibly, This allows you to perform Lambda calling Lambda locally by just setting a different endpoint something like: var lambda = new AWS.Lambda()
if(process.env.AWS_SAM_LOCAL) {
// only run inside local lambda runner
var ep = new AWS.Endpoint('localhost:3000');
var lambda = new AWS.Lambda({endpoint: ep})
} |
Thanks, Sanath for the reply. |
Yes, currently it is not supported, but it will be in the future. When it does, the feature will work similar to what you described. There will be only one endpoint. |
Does this work in SAM CLI, version 0.8.1? And configure lambda: And I sam local shows this error when invoke a lambda function from node on that endpoint: 2019-01-01 12:19:50 127.0.0.1 - - [01/Jan/2019 12:19:50] code 400, message Bad request version ('¤±\x8eé\x11C\x03D\x81\x17q=Ϣɴq/r9ïÉÖD:\x00"\x1a\x1a\x13\x01\x13\x02\x13\x03À+À/À,À0̨̩À\x13À\x14\x00\x9c\x00\x9d\x00/\x005\x00') Is there something else that needs to be done? |
I was able to get this to work on 0.6.0. I am running on mac, so I had to create my lambda with the following endpoint:
The issue I have now is that it doesn't appear that InvocationType of Event is supported. I wanted to use it as a fire and forget async call from one lambda to another (L1 --(async)-> L2), both running locally. When I update the InvocationType to be Event, I get a response of
|
I have created two lambdas -validateuserpermission and updateuserpermission. Here is the situation updateuserpermission calls validateuserpermission internally. "Could not connect to the endpoint URL: "http://127.0.0.1:3001/2015-03-31/functions/validateuserpermission/invocations\"" ON AWS console this is working but not able to work it from SAM local. However, if validateuserpermission invocation is removed from updateuserpermission , both lambda works fine in SAM LOCAL. Could you please help me in resolving this issue so that i would be able to test this situation. |
@surbhi029 127.0.0.1 in your endpoint_url is the virtual host for sam local, which is not the host as you'd expect. --host command line argument allows start-lambda to bind to a specific hostname or ip. You can try one that is accessible to your sam local virtual host. |
@renfeng how can i find a hostname or ip that is accessible to my sam local virtual host. |
@surbhi029 If you on mac or windows, use |
@jfuss Can you please provide me a little more guidance on the proper configuration to get This is essentially my setup:
I start
And then invoke with something like this:
In my
I get no errors but my |
OK. I figured out how to make this work. The following is what worked for me for anyone else encountering the same friction. First and VERY IMPORTANT... if you're using a Mac or Windows make sure you're using Docker Desktop and NOT Docker Toolbox. Docker Toolbox doesn't support Second... below is example code that works. At the time of me writing this, an invocation-type of 'Event' is not supported but hopefully soon (#749). You cannot use SSL so specify
Assuming you've configured any required environment variables correctly you should be in business. |
@sanathkr this should be
|
Hi,
|
Even though running start-api in the host network works as a workaround it would be great to have this feature directly in the CLI, is there any update on the subject? |
To anyone still having this issue... what solved it for us was that some of our lambdas are exposed through API Gateway whereas others are invoked directly (by other lambdas and not exposed through APIGW). We needed to do both |
@pkrisko -- does this require that you change all your "directly-invoked" lambdas back to their ARNs before deploying?
Am I understanding that correctly? EDIT: Fixed my own understanding. I'm using python3, so I needed to define my Boto3 lambda client to use the localhost endpoint for With this, I only need to define my boto3/lambda client and in my client.invoke()s I can simply use the FunctionName rather than the ARN. For others that find this be sure to define your region_name correctly.
EDIT2:
If I change the |
As I was trying to achieve a similar thing as the original poster I found that the information in this post are somewhat outdated and want to share my findings. Starting off with the scenario, I want to call LambdaA through API gateway running locally with After a way too long investigation I found in #2436 (comment) that using the host network cannot work anymore since sam version I cannot explain in depth what is going on as I'm not used to docker, especially networking, yet. What i know is that every container gets put into the I hope this solves this problem for some others. |
@jb3rndt thank you for the in depth analysis and for sharing your findings. I will give it a shot when I have the time. But wow! So many hurdles to jump through to have a reasonable local testing environment. I wish AWS serverless team would better acknowledge these drawbacks. |
@hburrows I can't seem to make this work on nodejs trying to figure this out for so long now. |
Hi everyone, Same issue here in 2021 😅 ... I'm a linux user and I tried the @jb3rndt solution but I can't seem to make this work, at least programatically. What I want :
ApiGateway ===> LambdaA ===> Lambda B What I got Step 1 it's ok, I can invoke lambdaA The code I'm using to invoke lambdaB is:
But the best part comes when I try to invoke lambdaB with aws cli and it works 😅
What's the difference between aws cli and invoke lambdaB from code ? any help ? I also tried to connect my containers to a new docker network using I don't know, maybe I missed something. any suggestions will be appreciated 😃 . |
I could not exactly figure out why yours is not working. I gave my best to create a minimal example that should be working. I hope you and other people can find out what is going different in your code and the example and find out why stuff is not working. Some things that might be different to your setup:
Generally, I found that the error "Invalid lambda response received: Lambda response must be valid json" is mostly caused by timeouts (in my case at least) which in turn are mostly caused by network endpoints that do not respond. In your case it is not clear to me whether lambdaB got invoked and did throw the 502 or whether lambdaB did not even get invoked 😅. So I hope that helps. |
Hey @jb3rndt, thank you for your investigation and your reply. I'm using linux and SAM CLI, version 1.35.0 To me, what worked is to call the target lambda using the command Thank you again for your advise! |
Thank you very much! @cezarmezzalira Changing the IP from Now I start de api server with
Now everything works as expected, and I can invoke multiple functions locally with no problems. |
We are in process writing an integration test for lambda.
Here is the situation LambdaA calls LambdaB internally.
Now I am invoking sam lambda A which internally call lmbdaB... ON AWS console this is working but not able to work it from SAM local.
However, if lambaB invocation is removed from LambdaA, both lambda works fine in SAM LOCAL.
Is this supported by SAM local, any workaround to move forward?
code snippets
var AWS = require('aws-sdk');
AWS.config.region = 'eu-west-1';
var lambda = new AWS.Lambda();
exports.handler = function(event, context,callback) {
var params = {
FunctionName: 'lambda-B', // the lambda function we are going to invoke
InvocationType: 'RequestResponse',
LogType: 'Tail',
Payload: JSON.stringify(event,null,null)
};
lambda.invoke(params, function(err, data) {
const dataPayload=data.Payload;
console.log("------dataPayload-----"+dataPayload);
console.log("------Now it should work-----"+JSON.parse(dataPayload).errorType);
if (err) { context.fail(err);
} else {
context.succeed('Lambda_SIGNATURE said '+ JSON.stringify(data));
}
The text was updated successfully, but these errors were encountered: