简体   繁体   中英

AWS SAM "No response from invoke container for" wrong function name

I've debugged my application, and identified a problem. I have 2 REST API Gateway, and it seems like since they both bind on the same endpoint, the first one will recieve the call that the second one should handle.

Here's my template.yaml

Resources:
  mysampleapi1: 
    Type: 'AWS::Serverless::Function'
    Properties:
      Handler: packages/mysampleapi1/dist/index.handler
      Runtime: nodejs14.x
      CodeUri: .
      Description: ''
      MemorySize: 1024
      Timeout: 30
      Role: >-
        arn:aws:iam:: [PRIVATE]
      Events:
        Api1:
          Type: Api
          Properties:
            Path: /users
            Method: ANY
      Environment:
        Variables:
          NODE_ENV: local
      Tags:
        STAGE: local
  mysampleapi2:
    Type: 'AWS::Serverless::Function'
    Properties:
      Handler: packages/mysampleapi2/dist/index.handler
      Runtime: nodejs14.x
      CodeUri: .
      Description: ''
      MemorySize: 1024
      Timeout: 30
      Role: >-
        arn:aws:iam:: [PRIVATE]
      Events:
        Api1:
          Type: Api
          Properties:
            Path: /wallet
            Method: ANY
      Environment:
        Variables:
          NODE_ENV: local
      Tags:
        STAGE: local

When I send a HTTP request for mysampleapi2

Here's what's happening in the logs using the startup command

sam local start-api --port 3001 --log-file /tmp/server-output.log --profile personal --debug
2022-04-27 18:2:34,953 | Mounting /home/mathieu_auclair/Documents/Project/repositories/server as /var/task:ro,delegated inside runtime container
2022-04-27 18:20:35,481 | Starting a timer for 30 seconds for function 'mysampleapi1'
2022-04-27 18:21:05,484 | Function 'mysampleapi1' timed out after 30 seconds
2022-04-27 18:21:46,732 | Container was not created. Skipping deletion
2022-04-27 18:21:46,732 | Cleaning all decompressed code dirs
2022-04-27 18:21:46,733 | No response from invoke container for mysampleapi1
2022-04-27 18:21:46,733 | Invalid lambda response received: Lambda response must be valid json

Why is my mysampleapi2 not picking the HTTP call? If I run them in separate template files using different ports, then it works... why is that?

After launching my lambda in separate processes, I discovered that there's an issue in my configuration for the second service.

The issue still occured after this launcher

echo "" > /tmp/server-output-1.log
sam local start-api --port 3001 --log-file /tmp/server-output-1.log --template .template.1.yaml --debug &
tail -f /tmp/server-output-1.log &

echo "" > /tmp/server-output-2.log
sam local start-api --port 3002 --log-file /tmp/server-output-2.log --template .template.2.yaml --debug &
tail -f /tmp/server-output-2.log &

I noticed when I exported my configuration, for one of the services, there's the following in the template.yaml

            Path: '/{proxy+}'

without the proxy line, the lambda handler just never gets called for some reason

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM