Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

272
Views
Invoke SAM Lambda from Lambda locally

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.

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!