Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

273
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda