aws-sam-cli icon indicating copy to clipboard operation
aws-sam-cli copied to clipboard

SAM local - Error: Template does not have any APIs connected to Lambda functions

Open armandAkop opened this issue 4 years ago • 4 comments

Description:

I am using SAM to create a step function with a local API gateway to test some functionality. I can build the template fine, but when I run using sam local start-api -t my_template.yaml --debug, I get this error

Error: Template does not have any APIs connected to Lambda functions

Steps to reproduce:

Template file

AWSTemplateFormatVersion: "2010-09-09"
Transform: "AWS::Serverless-2016-10-31"
Description: Event driven architecture for creating and uploading PDFs to Box.
Resources:
  UploaderStateMachine:
    Type: AWS::Serverless::StateMachine
    Properties:
      Name: uploader-state-machine
      DefinitionUri: my_definition.json
      Events:
        MyApi:
          Type: Api
          Path: /
          Method: POST

Observed result:

2021-03-22 13:41:47,899 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2021-03-22 13:41:47,899 | Using config file: samconfig.toml, config environment: default
2021-03-22 13:41:47,899 | Expand command line arguments to:
2021-03-22 13:41:47,899 | --template_file=/Users/johndoe/projects/test-service/serverless/my_template.yaml --host=127.0.0.1 --port=3000 --static_dir=public --layer_cache_basedir=/Users/johndoe/.aws-sam/layers-pkg 
2021-03-22 13:41:48,007 | local start-api command is called
2021-03-22 13:41:48,011 | No Parameters detected in the template
2021-03-22 13:41:48,039 | 1 stacks found in the template
2021-03-22 13:41:48,039 | No Parameters detected in the template
2021-03-22 13:41:48,060 | 1 resources found in the stack 
2021-03-22 13:41:48,060 | No Parameters detected in the template
2021-03-22 13:41:48,090 | No Parameters detected in the template
2021-03-22 13:41:48,109 | No Parameters detected in the template
2021-03-22 13:41:48,130 | Removed duplicates from '0' Explicit APIs and '0' Implicit APIs to produce '0' APIs
2021-03-22 13:41:48,130 | 0 APIs found in the template
2021-03-22 13:41:48,135 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '01f63b20-53d6-42d2-902f-d85dbe016f7c', 'installationId': '822dc94d-3c39-4026-969d-ae9c01b7f5ba', 'sessionId': 'f69e676b-5c19-4c91-b252-363743a4febd', 'executionEnvironment': 'CLI', 'pyversion': '3.8.8', 'samcliVersion': '1.21.1', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam local start-api', 'duration': 235, 'exitReason': 'NoApisDefined', 'exitCode': 1}}]}
2021-03-22 13:41:48,451 | Telemetry response: 200
Error: Template does not have any APIs connected to Lambda functions

Expected result:

I thought an API gateway would be created locally for me to use if I didn't explicitly create one.

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: Mac OSX Catalina (10.15.7)
  2. sam --version: 1.21.1
  3. AWS region: just testing locally

Add --debug flag to command you are running

armandAkop avatar Mar 22 '21 20:03 armandAkop

sam local start-api command currently only supports the API Gateway connected to Lambda functions, it does not support testing API Gateway resources connected to StepFunction.

moelasmar avatar Mar 25 '21 09:03 moelasmar

Ah okay, makes sense. Thank you.

armandAkop avatar Mar 25 '21 16:03 armandAkop

I would love to help build this feature. Is there any roadmap or rough idea for implementing this?

Would it make sense for example to make use of the amazon/aws-stepfunctions-local Docker image to offload some of the required functionality?

jvhoven avatar May 28 '21 07:05 jvhoven

this still needs followup in 2024.

slavanorm avatar Jul 22 '24 11:07 slavanorm