5

I would like to offload some functionality from my Lambda@Edge to speed up response time. This would mean triggering another Lambda Function inside my Lambda@Edge.

Lambda@Edge distributes the application across all regions, so when a request is made it would execute the application in the region closest to the requester.

My current solution is to create an SNS with the same topic name on all regions, have an SQS in us-east-1 listen to all these SNS Topics, and the Lambda function to listen to the SQS.

However, creating an SNS on every region is quite a hassle to maintain.

Any other suggestions on how I can trigger another Lambda function inside my Lambda@Edge?

Thanks!

naribo
  • 690
  • 8
  • 19

1 Answers1

1

Within lambda you can simply make the call to another lambda. I don't know which language you are using, but here is an example in Python and the boto3 library with a sample payload of information you may want to pass on to the lambda being invoked (I used region and detail-type as example info to pass along):

payload = {'region': <the region>, 'detail-type': 'some other detail you care about'}
lambda_client = boto3.client('lambda', account_id=<your account ID>)
lambda_client.invoke(FunctionName=<ARN of the function you want to invoke>, InvocationType='Event', Payload=json.dumps(payload))

Similar options are available in other languages. More details for this call in Python are at https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/lambda.html#Lambda.Client.invoke

Shawn
  • 8,374
  • 5
  • 37
  • 60