Search code examples
amazon-web-servicesasynchronousaws-lambdaamazon-sqsamazon-sns

Asynchronously invoke lambda functions


I need to asynchronously invoke lambda functions from my EC2 instance. At high level, so many services come to my mind(most likely all of these support my desired functionality) - AWS State machine(not sure), step functions, Active MQ, SQS, SNS. I am aware about pros and cons of each at high level. However not sure which one should I go for :|. Please let me know your feedback.

PS: We expect the invocation in 1000s per second at peak for very short periods. Concurrency for lambda functions is not an issue as we can ask Amazon for increase in the limit along with the burst.


Solution

  • If you want to invoke asynchronously then you can not use SQS as SQS invoke lambda function synchronously with event source mapping.

    You can use SNS to invoke lambda function asynchronously out of the option you listed above.

    Better option would be writing small piece of code in any AWS SDK whichever you are comfortable and then call lambda function from that piece of code asynchronously.

    Example in python using boto3 asynchronously pass Event in InvocationType to invoke lambda function asynchronously and pass RequestResponse to invoke lambda function synchronously

    client = boto3.client('lambda')
    response = client.invoke(
            FunctionName="loadSpotsAroundPoint",
            **InvocationType='Event',**
            Payload=payload3