Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I call AWS Lambda directly without Gateway API?

I am developing a simple Lambda function on AWS to get and put data into Dynamo DB. I wanted to call this function from the Windows Client desktop application. My question is, do I really need AWS Gateway API here or can I call the lambda function directly using AWS SDK?

like image 270
Sam K Avatar asked Mar 21 '26 23:03

Sam K


2 Answers

You can use invoke() to directly execute an AWS Lambda function from an AWS SDK. You can also pass it a payload, which will be accessible within the function.

Here is a syntax example in Python:

response = client.invoke(
    ClientContext='MyApp',
    FunctionName='MyFunction',
    InvocationType='Event',
    LogType='Tail',
    Payload='fileb://file-path/input.json',
    Qualifier='1',
)
like image 114
John Rotenstein Avatar answered Mar 23 '26 12:03

John Rotenstein


  • You need API Gateway if you want to create REST APIs that mobile and web applications can use to call publicly available AWS services (through code running in AWS Lambda).
  • You can synchronous invoke your Lambda functions. This can be accomplished through a variety of options, including using the CLI or any of the supported SDKs. Note the invocation-type should be RequestResponse aws blog
  • bash command using aws cli
aws lambda invoke —function-name MyLambdaFunction —invocation-type RequestResponse —payload  “JSON string here”

sdk python call. configuration

    invoke_resp = LAMBDA_CLIENT.invoke(
        FunctionName='function_name',
        InvocationType='RequestResponse',
        Payload='payload')
  • If you want to invoke the lambda asynchronous Invocation-type flag should be Event
aws lambda invoke —function-name MyLambdaFunction —invocation-type Event —payload  “JSON string here”
like image 25
amittn Avatar answered Mar 23 '26 11:03

amittn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!