Aws-sam-cli: Running serverless application locally

Created on 15 Jul 2019  ยท  6Comments  ยท  Source: aws/aws-sam-cli

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

priorit3-long-term typfeature

Most helpful comment

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?

All 6 comments

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.

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?

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...

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

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.

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

enghwa picture enghwa  ยท  25Comments

terrywarwar picture terrywarwar  ยท  26Comments

burck1 picture burck1  ยท  45Comments

ztolley picture ztolley  ยท  28Comments

0xdevalias picture 0xdevalias  ยท  27Comments