1

Consider a piece of serverless code:

functions:
  MyFunc:
    handler: index.handler
    name: "my_name"
    runtime: nodejs12.x
    memorySize: 512
    timeout: 30
    inlineCode: |
      exports.handler = function(event, context) {
          console.log("ok");
      };
    description: description 

This leads to pacakge everything in source folder. I can not disable it. Event if I add:

package:
  artifact: dummy.zip

Deploy failed because dummy.zip is empty file. But why I need a zip file when specified inlineCode? Is there a way to disable packaging and deploy nodejs function with inlineCode parameter only?

2 Answers 2

1

The concept of an inlineCode parameter is supported by AWS::Serverless::Function, but not serverless-framework. The YAML you pasted is not a 1:1 mapping to the AWS::Serverless::Function, it's specific to sls itself.

Store your code in files/directories until the sls team adds support for inlineCode. I didn't see any feature requests for it. I'm sure they'd be glad to get one from you.

Sign up to request clarification or add additional context in comments.

1 Comment

` I'm sure they'd be glad to get one from you.` - If I have a time... :-)
1

The workaround is to define lambda function deginition as normal cloudformation resource like that:

resources:
  Resources:
    MyFunc:
      Type: AWS::Lambda::Function
      Properties:
        FunctionName: "my_name"
        Handler: index.handler
        Runtime: nodejs10.x
        Role: !GetAtt LambdaRole.Arn # do not forget to define role by hand :(
        Code:
          ZipFile: |
            exports.handler = function(event, context, callback) {
            console.log(event);
                const response = {
                    statusCode: 200,
                    body: JSON.stringify('Hello Node')
                };
                callback(null, response);
            };

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.