Sam K
Sam K

Reputation: 408

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?

Upvotes: 3

Views: 4398

Answers (3)

Nghia Do
Nghia Do

Reputation: 2668

I don't have much information from your use case. I have to assume something here.

  1. You don't need to wait for the response back from Lambda So you can use async call through SNS or SQS and then put your Lambda subscribed for either SNS or SQS. You can research more to choose between SNS and SQS, depends on your use case

  2. If you need to wait for the response back from Lambda

    • If you want to share the Lambda's feature outside your organization, you can use API Gateway to do so, it means you still keep Lambda inside but expose an API through API Gateway to outside for usage.

    • If you don't want to share the Lambda's feature outside, like previous answers, you can use invoke command/sdk to achieve the result.

If I have more information from your use case, maybe the answer can be more accurate.

Upvotes: 2

amittn
amittn

Reputation: 2355

  • 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”

Upvotes: 2

John Rotenstein
John Rotenstein

Reputation: 270264

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',
)

Upvotes: 2

Related Questions