aws / aws-sam-cli

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
https://aws.amazon.com/serverless/sam/
Apache License 2.0
6.51k stars 1.17k forks source link

Running local api for nested serverless application locally #1271

Closed gerhardberger closed 3 years ago

gerhardberger commented 5 years ago

I have a serverless SAM-based service that has multiple Application resource referencing local templates, but running the template locally (with sam local start-api) doesn't seem to recognize the nested applications.

Is it possible to run all of the referenced Applications as a single service locally?

Thanks

awood45 commented 5 years ago

Can you describe this use case in a bit more detail? Something like an example of the template(s) would be useful for scoping this work. Feel free to anonymize out any details, mostly interested in the different templates and how they're relating to each other.

netochaves commented 4 years ago

Facing the same problem here, I'll try to add more context to the problem.

My team has multiple template.yml each template represent an API that we use, see the graph bellow:

src/
│   ├── contracts/
│   │    └── functions...
│   │    └── template.yml
│   ├── simulations/
│   │    └── functions...
│   │    └── template.yml
|   └── template.yml

So contracts and simulations will have their own template.yml that will contain all lambdas declarations and events. Then on template.yml of src we declare this API's as nested applications, like this:

Resources:
  APIDomainName:
    Type: "AWS::ApiGateway::DomainName"
    Properties:

  # # API: Contracts
  ContractsApp:
    Type: AWS::Serverless::Application
    Properties:
      Location: src/contracts/template.yaml
      Parameters:

  # # API: Simulations
  SimulationsApp:
    Type: AWS::Serverless::Application
    Properties:
      Location: src/simulations/template.yaml
      Parameters:

What we want is that when we start a local api with sam local start-api on src folder their nested applications will be started too with their API's. Currently, an error is returned because we do not have any http event on this template.yml (this events are on the nested applications).

This will be an awesome feature to sam thanks for this CLI btw.

@gerhardberger Do you find any workaround for this?

made2591 commented 4 years ago

Hi, we also would like to have a feature like that: right now, during development, we use to run local start-api over the single nested stacks, but it doesn't scale a lot...

elenasch commented 4 years ago

I have a very similar use as as @netochaves , with exception of running sam local start-lambda . Is there any word on making this happen ? I'm worried that without this, my team won't be able to scale development with lambdas

ashutoshtripathi commented 4 years ago

We are facing same issue when working with multiple child stacks. Rootstack (yaml) -Child1 (yaml) (all apis) -Child2(yaml) (few events)

Command & output: sam local start-api --parameter-overrides EnvironmentValue=Dev Error: Template does not have any APIs connected to Lambda functions

Command & output: sam local start-api --parameter-overrides EnvironmentValue=Dev -t Child1_api.yaml Error: Fn::FindInMap is an Invalid Layer Arn.

alayor commented 3 years ago

Can everybody use the thumbs-up react on the first comment so this can have a higher visibility for the dev team?

aahung commented 3 years ago

start-api detecting APIs in nested stack has been implemented in #2662, to be released

aahung commented 3 years ago

released in v1.20.0