question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

template.yml inside folder breaks 'sam local invoke'... still

See original GitHub issue

see this: https://github.com/awslabs/aws-sam-cli/issues/140 Same problem with version: version 0.3.0

Uninstalled sam npm, upgraded to latest sam local with pip (python 2)

Windows 10.

sam local invoke blah --template mytemps/mytemp.yaml -e myevents/test.json
Unable to import module 'lambda_function': No module named 'lambda_function'

Works when yaml template is in the root of the folder. Do I have to use codeUri or something?

YAML

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: An AWS Serverless Specification template describing your function.
Resources:
  blah:
    Type: 'AWS::Serverless::Function'
    Properties:
      Handler: lambda_function.lambda_handler
      Runtime: python3.6
      Description: ''
      MemorySize: 128
      Timeout: 300
      Role: '......'
      Environment:
        Variables:
          sdfsdfs: sdfsdfsdf

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
red8888commented, Jun 18, 2018

Welp im dumb looks like this is working. i just needed to copy my code to a different folder and use CodeUri to point to it.

0reactions
jsheedycommented, Oct 8, 2018

I came here with a similar problem and @red8888’s suggestion to modify CodeUri helped me solve it.

When running with the template in a subdirectory:

sam local start-api -p 9090 --host 0.0.0.0 --template project/template.yml

I got errors about my handler module not being found. When I moved template.yml to the current directory it worked as expected.

The fix was to update the path of CodeUri

from build/project.zip to ../build/project.zip

The structure is like this:

root
  project
    template.yml
  build
    project.zip

and I run the sam local command from inside the root directory.

Read more comments on GitHub >

github_iconTop Results From Across the Web

template.yml inside folder breaks 'sam local invoke'... still
So for example you have your template in a subfolder named "mytemps". If you copy your code to another subfolder named "mycode" ,...
Read more >
sam local invoke - AWS Serverless Application Model
The AWS SAM CLI first tries to locate a template file built using the sam build command, located in the .aws-sam subfolder, and...
Read more >
AWS SAM: Could not install from function as it does not ...
The hello-world sample project generated with sam init doesn't have one in the root folder either, but somehow sam build has no problem ......
Read more >
DEEP DIVE INTO AWS SAM BUILDING AND PACKAGING ...
In this episode I talk to Eric Johnson, Developer Advocate for Serverless at AWS and we go into de depths of AWS SAM...
Read more >
awslabs/aws-sam-local
The reason I want to change it is in handler, I will return a data map and it works on real lambda connected...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found