Home > Software design >  Passing configuration information to an AWS Lambda function
Passing configuration information to an AWS Lambda function

Time:01-14

I have an AWS Labmda function which synchronises a remote feed of content to an S3 bucket. It needs to be run periodically so is currently called hourly using a CloudWatch cron event.

This works great for a single feed, however I now need multiple feeds to be synchronised which can use exactly the same functionality just with a different source URL and bucket.

Rather than clone the entire Lambda function for each feed, is there some mechanism to pass configuration information into the Lambda invocation to specify what it should be operating on?

The function is written in Node 14.x in case that is significant.

CodePudding user response:

Yes it is possible,

enter image description here

In the above image you can start a CRON JOB for Lambda A and then it can pass that information as payload using asynchronous calls to 2nd Lambda. This will execute the 2nd Lambda concurrently and thus you can execute as many as 1000 concurrent executions.

It's a fan-out pattern and it can be implemented in your scenario.

CodePudding user response:

For this you have 2 options:

In the same function, change environment variables, publish a version, and attach it to ALIAS. Each published version saves its own values for environment variables. With this approach, the problem is if you want to make some change in the code, you would have to re-publish the function for each alias again (and change all the environment variables each time) so this is error-prone.

The second option is to pass the config details through the event param that Lambda accepts (as a JSON) and read in in the Lambda function. You can have separate Cloudwatch events which will pass different JSON event details.

  •  Tags:  
  • Related