Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow inline Lambda function definitions #6872

Open
trilom opened this issue Oct 23, 2019 · 2 comments
Open

Allow inline Lambda function definitions #6872

trilom opened this issue Oct 23, 2019 · 2 comments

Comments

@trilom
Copy link

trilom commented Oct 23, 2019

Feature Proposal

Description

  1. What is the use case that should be solved. The more detail you describe this in the easier it is to understand for us.
    For some very simple lambda functions, such as CustomResources, it would be very useful to be able to define our function code in line. This way I can reduce footprint of infrastructure from 2 files (serverless.yml and function code file) to 1 file (serverless.yml with function code defined inline).

Here is an example of a similar enhancement defined in SAM for the same use case.

  1. Optional: If there is additional config how would it look
    Here is an example of the usage.
service: custom-resource

provider:
  name: aws
  runtime: python3.7

functions:
  crFunction:
    handler: handler.handler
    code: |
        print('Here')


resources:
  Outputs:
    crFunction:
      Value: !GetAtt CrFunction.Arn
      Export:
        Name: "CrFunction"

plugins:
  - serverless-python-requirements
@Lokesh-Jawale
Copy link
Contributor

I will like to work on this feature. @medikoo can you assign this to me?

Considered points for inline code for lambda function:

  • Supported languages : python and node.js
  • For the Handler property of lambda function, the first part of the handler identifier must be index. For example, index.handler.
  • code size limit : 4mb
  • For JSON, you must escape quotes and special characters such as newline (\n) with a backslash.

Below is the configuration for providing inlineCode to the lambda function.
The relation to its generated cloud formation template will be
cfTemplate:

Code:
    ZipFile: |
        print("Hello World!")

serverless config

functions:
  sayHello:
    handler: sayhello.handler
    code:
        inlineCode: |
            print("Hello World!")

@medikoo
Copy link
Contributor

medikoo commented May 26, 2023

@Lokesh-Jawale let's leave it to plugin authors. It looks as invasive feature for which demand is very low, so I don't think it should land as part of a core.

Only issues with help wanted or good first issue tag are open for implementation (or spec discussion, see details in issue)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants