Reputation: 321
I have microservice that contains multiple Lambda functions.
How can I share the same code between those functions?
Lets imagine I have the following structure:
handler
|
|______ a-handler.js
|
|______ b-handler.js
|
repository
|
|______ users-repository.js
I know that AWS recommended to use Lambda Layers for that, but can I simply import the relevant code to the Lambda function?
Like that:
users-repository.js:
export getUser(...){...};
export createUser(...){...};
a-handler.js:
import {getUser} from '../repository/users-repository.js';
/.../
b-handler.js:
import {createUser} from '../repository/users-repository.js';
/.../
The build process anyway will do Tree Shaking and remove the unused code from the Lambda function, so basically it will use and build only the relevant code.
So what are the benefits of Lambda Layers?
Thanks!
Upvotes: 2
Views: 1427
Reputation: 22251
There’s no mandate to use layers to share code. The reasons I’ll end up with a layer over an include are:
Includes has more or less the opposite set of use scenarios:
Upvotes: 2