Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

I am designing a serverless application with AWS Lambda. There's a piece of code on one of the functions that process the request in a certain way. I am going to make another function that's going to make the same processing with the request data, in the same way.

The problem is that, if I change the processing function in one of the Lambda functions, I'm going to have to copy the function and paste in the other Lambda function. Every time I make a change I will have to do this. This will be yet more cumbersome if I want to do the same processing function in more than two Lambda functions.

Is there a way to share pieces of code between Lambda functions, so I may respect DRY principles?

1 Answer

0 votes
by (44.4k points)

Layers can be used in Lambda to share libraries and code between your various functions.

Like how you create a ZIP file for the function, you have to create for the Layers. So if you have a file structure like this:

bundle.zip/

  python/

    common/

      __init__.py

      lib.py

Then in your Lambda function, you can reference those libraries like this:

from common.lib import ...

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
3 answers
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...