1

I am familiar with invoking lambda from another lambda and also to pass param to handler function based on which it calls different methods from a service(Same as stated here AWS Lambda - Invoke a method of another lambda function), But when there is a case to expose all the methods of a service its quite tedious to add multiple condition in the handler function.

So my question is Is there any dynamic way we can expose all the methods of the service using single lambda handler function, or may be any other efficient way. My main motive is to expose whole method in a service using lambda handler so that I don't have to add different conditions and another lambda can invoke it method name without any conditional parameter.

Sample code here

export const handler = async function(params: params, context: Context, callback: Callback) { if(params.type === 'type1'){ const results = await testService.testmethod1(params.value); context.succeed(results); } else if(params.type === 'type2'){ const results = await testService.testmethod2(params.value); context.succeed(results); } and so on... }; 

So Is there any way we can expose all methods of testService(above we have exposed to methods testmethod1 and testmethode, there can be other methods as well) without all these conditional statements?

5
  • Can you post code to clarify what you are asking? Commented Sep 11, 2020 at 9:45
  • @tom-redfern I have updated the question with code now. Commented Sep 11, 2020 at 10:01
  • Why you want to access method of lambda inside another lambda. Directly pass respective params lets that executor lambda handle mapping to respective function. Commented Sep 11, 2020 at 10:15
  • I am exposing these methods of a service as a library so that other repository can access these methods using that library. Commented Sep 11, 2020 at 10:17
  • As the answer to the other question you linked says, the one and only entry point of a lambda function is its handler, so you'll have to pass your parameters to it and then inside said handler you can have your conditional logic. A lambda function is conceptually not the same as an object/class so there's no such thing as methods. If you have a module/library that you want to use throughout your lambda functions just create a library and add it to the deployment package of each function or as a Lambda Layer. Commented Sep 11, 2020 at 14:56

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.