Skip to content

sam local invoke command does not support !Sub function keyword in Layers settings #948

@goldeneggg

Description

@goldeneggg

Description

There is a example how to use Layers in serverless-application-model/2016-10-31.md

2019-01-20 0 32 01

But it does not work at local.

Steps to reproduce

The template.yaml below

  • Use !Sub function and "${AWS::Region}" parameter in Layers section
  • Layer function "arn:aws:lambda:${AWS::Region}:123456789012:layer:MyLayer:1" is already deployed
Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: hello_world/
      Handler: app.lambdaHandler
      Runtime: nodejs8.10
      Events:
        HelloWorld:
          Type: Api
          Properties:
            Path: /hello
            Method: post
      Layers:
        - !Sub arn:aws:lambda:${AWS::Region}:123456789012:layer:MyLayer:1

Run sam local invoke and get an error as follows

$ sam local invoke -e event.json HelloWorldFunction

Unable to import module 'app': Error  # This is an error about module include of Node.js

On the other hand, the template.yaml below works correctly at local.

  • Don't use !Sub function
    • use literal string value. (e.g. "ap-northeast-1")
Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: hello_world/
      Handler: app.lambdaHandler
      Runtime: nodejs8.10
      Events:
        HelloWorld:
          Type: Api
          Properties:
            Path: /hello
            Method: post
      Layers:
        - arn:aws:lambda:ap-northeast-1:123456789012:layer:MyLayer:1
$ sam local invoke -e event.json HelloWorldFunction

Downloading arn:aws:lambda:ap-northeast-1:123456789012:layer:MyLayer:1  [####################################]  7298732/7298732

{"statusCode":200,"body": ...

Why?

Because this method support literal string but does not support !Sub keyword.

Expected result

I think reason for error should be warned.

$ sam local invoke -e event.json HelloWorldFunction

2019-01-20 00:56:43 '!Sub' keyword in Layer configuration does not work at local. Please replace all parameter strings(like '${AWS::Region}') with the original value and remove '!Sub' keyword from template.yaml .

Unable to import module 'app': Error

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

  1. OS: OS X (Mojavi)
  2. sam --version: "SAM CLI, version 0.10.0"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions