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.

InlineCode not working for sam invoke

See original GitHub issue

Description:

Trying to add InlineCode (node) in the tamplate file. Getting an error:

Invoking app.lambdaHandler (nodejs10.x)
Traceback (most recent call last):
  File "/usr/local/bin/sam", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/Cellar/aws-sam-cli/1.21.1/libexec/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/1.21.1/libexec/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/usr/local/Cellar/aws-sam-cli/1.21.1/libexec/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/Cellar/aws-sam-cli/1.21.1/libexec/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/Cellar/aws-sam-cli/1.21.1/libexec/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/Cellar/aws-sam-cli/1.21.1/libexec/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/1.21.1/libexec/lib/python3.8/site-packages/click/decorators.py", line 73, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/1.21.1/libexec/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/1.21.1/libexec/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 152, in wrapped
    raise exception  # pylint: disable=raising-bad-type
  File "/usr/local/Cellar/aws-sam-cli/1.21.1/libexec/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 121, in wrapped
    return_value = func(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/1.21.1/libexec/lib/python3.8/site-packages/samcli/lib/utils/version_checker.py", line 42, in wrapped
    actual_result = func(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/1.21.1/libexec/lib/python3.8/site-packages/samcli/cli/main.py", line 90, in wrapper
    return func(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/1.21.1/libexec/lib/python3.8/site-packages/samcli/commands/local/invoke/cli.py", line 81, in cli
    do_cli(
  File "/usr/local/Cellar/aws-sam-cli/1.21.1/libexec/lib/python3.8/site-packages/samcli/commands/local/invoke/cli.py", line 167, in do_cli
    context.local_lambda_runner.invoke(
  File "/usr/local/Cellar/aws-sam-cli/1.21.1/libexec/lib/python3.8/site-packages/samcli/commands/local/lib/local_lambda.py", line 120, in invoke
    config = self.get_invoke_config(function)
  File "/usr/local/Cellar/aws-sam-cli/1.21.1/libexec/lib/python3.8/site-packages/samcli/commands/local/lib/local_lambda.py", line 163, in get_invoke_config
    code_abs_path = resolve_code_path(self.cwd, function.codeuri)
  File "/usr/local/Cellar/aws-sam-cli/1.21.1/libexec/lib/python3.8/site-packages/samcli/lib/utils/codeuri.py", line 43, in resolve_code_path
    if not os.path.isabs(codeuri):
  File "/usr/local/Cellar/python@3.8/3.8.8_1/Frameworks/Python.framework/Versions/3.8/lib/python3.8/posixpath.py", line 62, in isabs
    s = os.fspath(s)
TypeError: expected str, bytes or os.PathLike object, not NoneType

Steps to reproduce:

  • setup hello world example with sam init
  • add InlineCode property to HelloWorldFunction Relevant part of the template:
Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      # CodeUri: hello-world/
      InlineCode: |
        exports.handler = async (event) => {
          return {
            statusCode: 200,
            headers: {'Content-Type':'application/json'},
            body: "hello"
            }
        }
      Handler: app.lambdaHandler
      Runtime: nodejs10.x
      Events:
        HelloWorld:
          Type: Api
          Properties:
            Path: /hello
            Method: get

Observed result:

Getting error above

Expected result:

Function should run

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

  1. OS: Macos 11.2.3
  2. sam --version: SAM CLI, version 1.21.1

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
qingchmcommented, Apr 5, 2021

Sorry my bad, just confirmed that local invoke with inline code is not yet supported! Will view this as a feature request. But please keep using this style of handler for inline functions, thanks! @mihaa1

0reactions
jfusscommented, Apr 13, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

Function - AWS Serverless Application Model
This property addresses a problem that occurs when an AWS SAM template has ... The object that describes event invoke configuration on a...
Read more >
Output FunctionUrl from AWS::Serverless::Function with URL
I saw the AWS::Lambda::Url resource created by SAM but was not sure if it was accessible from the untransformed template. Add your answer....
Read more >
Getting started with the AWS SAM CLI | by Aveek Das
With the help of this utility, you can easily define your resources and get those deployed to any environment in the AWS without...
Read more >
AWS SAM for a serverless Java application - Medium
Now let's create a POJO class for our data model. To simplify work with DynamoDB, let's use AWS SDK version 2 for Java,...
Read more >
Introduction to SAM Part II: Template and architecture
CloudFormation recognises a top-level template key Transform: AWS::Serverless-2016-10-31 and invokes the SAM Translator if it is found.
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