3

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?

3 Answers 3

2

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',
)
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, John! I am not really looking for the code. What I want is why do we need API Gateway
You don't need API Gateway. You can call Lambda directly (as shown in my example above). Or, you can call it via the AWS Command-Line Interface (CLI).
2
  • 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”

Comments

2

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.