I am trying to use sam local to invoke a lambda function (LambdaB) from a separate Lambda function (Lambda A), and can't seem to figure out how to wire the two of them up.
I have 2 lambdas, defined in template.yml as
LambdaA:
Type: AWS::Serverless::Function
Properties:
FunctionName: LambdaA
Handler: lambdas/api/Lambda/main.handler
Description: The function related to <Removed>
Role: '<Removed>'
MemorySize: 1024
Timeout: 900
Policies:
- LambdaInvokePolicy:
FunctionName: !Ref LambdaB
Environment:
Variables:
UPLOAD_FUNCTION: !Ref LambdaB
Events:
Api:
Type: Api
Properties:
RestApiId: !Ref ApiGateway (Defined above)
Path: /LambdaA
Method: Any
LambdaB:
Type: AWS::Serverless::Function
Properties:
FunctionName: LambdaB
Handler: lambdas/api/Lambda/upload.handler
Description: Specialized function to upload files
Role: '<Removed>'
MemorySize: 1024
Timeout: 60
The code in LambdaA to invoke LambdaB is as follows:
const lambdaClient = new aws.Lambda({
endpoint: 'http://127.0.0.1:3002',
sslEnabled: false,
});
var lambdaParams = {
FunctionName: 'LambdaB',
InvocationType: 'RequestResponse',
Payload: '{ "name" : "Alex" }',
};
let resp = await lambdaClient.invoke(lambdaParams).promise();
I have spun up a local API with sam local start-api -p 3001, Which is how I invoke LambdaA.
I have also spun up a local Lambda instance with sam local start-lambda -p 3002.
Both of these display to the console that they are running at http://127.0.0.1:3001/ and http://127.0.0.1:3002/ respectively.
I am running on an m1 macbook, and I have tried multiple permutations of changing the lambda client endpoint, such as "localhost", "host.docker.internal", "172.17.0.1" and more. I've also tried setting the host of both start-api and start-lambda to 0.0.0.0. Every permutation results in LambdaA being invoked correctly, but requests to LambdaB result in Error UnknownEndpoint: Inaccessible host: `127.0.0.1' at port `3002'. This service may not be available in the `us-east-2' region.
I'm at a loss for where to go in my debugging, as I don't have a whole lot of networking experience.