0

I am trying to write a simple API's using Amazon AWS API gateway with Lambda integration.

Lambda function to some computation by reading user input and some configuration.

How can I make both API's or lambda functions to use the same configuration without duplicating?

Correct me if i am using API gateway in wrong way.

5
  • Would you give an example of what you are trying to achieve? Commented Jun 9, 2018 at 12:50
  • I am writing some analytics api where it extracts information from different machines. machine ip address mapping is given as config. two lambda functions should able to read the config. Commented Jun 9, 2018 at 12:56
  • Can you provide the code you that should be shared? Commented Jun 9, 2018 at 12:59
  • pseudocode : gist.github.com/rajeevprasanna/33425fe457a6d346e6a2c622863c2aaa Commented Jun 9, 2018 at 13:16
  • 1
    You can store the config in s3 and read it in each Lambda. Commented Jun 9, 2018 at 19:07

1 Answer 1

1

Two ways I can think of:

  1. Create another lambda function which executes the common logic and invokes the corresponding lambda function with the data it processed. In your case:

    def lambda_handler(event, context):    
        config = load config from env variable.
        take service names from user input(event)
        extract corresponding micro services names mapped to feature name.
        check event.methodName to see which function to call next
        invoke {event.methodName}Lambda with the data
    
  2. (Recommended) Consider using Serverless where you define env variables only once and you can extract common logic into separate (non-lambda) functions which you can reuse in multiple lambda functions

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.