volume_mute

Select the best practices you should consider when creating a Lambda function

publish date2024/08/30 00:37:18.817848 UTC

volume_mute
Separate business logic
Add your business logic to the handler event
Write modular functions
Treat functions as stateless
Maintain states in your function
Only include what you need

Correct Answer

(1) Separate business logic
(2) Write modular functions
(3) Treat functions as stateless
(4) Only include what you need

Explanation

When designing and writing Lambda functions, regardless of the runtime you’re using, it is best practice to separate the business logic (the part of the code the defines the real-world business need) from the handler method. This makes your code more portable and you can target unit-tests at the code without worrying about the configuration of the function. 

It is also a best practice to make your functions modular. For example, instead of having one function that does compression, thumb-nailing, and indexing, consider having three different functions that each serve a single purpose. 

Because your functions only exist when there is work to be done, it is particularly important for serverless applications to treat each function as stateless. That is, no information about state should be saved within the context of the function itself. 

Reference

AWS Skill Builder


Quizzes you can take where this question appears