-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Description
Description
There is a example how to use Layers in serverless-application-model/2016-10-31.md
But it does not work at local.
Steps to reproduce
The template.yaml below
- Use
!Subfunction and "${AWS::Region}" parameter inLayerssection - 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:1Run 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.jsOn the other hand, the template.yaml below works correctly at local.
- Don't use
!Subfunction- 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': ErrorAdditional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: OS X (Mojavi)
sam --version: "SAM CLI, version 0.10.0"
Reactions are currently unavailable
