I am new to AWS and I am setting up a API Gateway which will call a Lambda function that will post that data to a Kinesis Stream. The API Gateway Post request will contain several request parameters.
I am reading through the AWS docs and I see 2 options for accessing the request parameters.
1) Via the $input Variable doc
2) via Proxy Integration doc
Can you please explain the use case for proxy integration vs using the input variable?
Basically, if you control the backend integration interface (as you would with a Lambda function) you should use the 'proxy' integration because it's much easier to manipulate the data in your Lambda function code than in the API Gateway transformation.
If you don't control the backend integration interface (like Kinesis directly, or a legacy HTTP endpoint for example) then you can use the mapping template to transform the data between the client and the backend integration.
Does that make sense? For your use case using Lambda, you should use the proxy. If you wanted to try to use Kinesis directly as the backend, you would have to use a mapping template to construct the correct request to Kinesis.
Related
I have an API in AWS API Gateway (API GW) with the integration type configured as a Lambda Proxy (it means that automatically maps the request data to the event of the lambda function)
There are a lot of microservices using that API GW, I want set a mocked response based on the Payload without:
adding new methods with different integration types
adding new logic to the backed hitted by the API GW method
modifying the request made by the microservices to hit a new endpoint / using new method / add query parameters
So, is it possible to skip the backend call, and just send a mocked response looking for a flag in the existing payload (keeping in mind that the integration type is a Lambda Proxy)?
Since there is aditional costs for using HTTP and REST apis on AWS lambda, i would like to know if i could make AWS Lambda receive gets and posts without the need of these HTTP API services.
In this example it seems to be possible:
https://github.com/serverless/examples/tree/master/aws-node-simple-http-endpoint
You will need to use the API Gateway to expose your lambda. Your example is actually using an API Gateway, because the endpoint is execute-api.us-east-1.amazonaws.com and that is the Amazon API Gateway Data Plane.
Just to be clear; if you need to expose the Lambda externally you need to use the API Gateway. If the Lambda needs to be invoked internally then you don't need the API GW.
Best regards
Lambda also exposes a client API in all languages. Therefore, you can invoke a Lambda function by using the client API (not use API Gateway if you prefer). For example, assume you want the ability to invoke a Lambda function from a Java web app. In this situation, you can use the LambdaClient object to do so. You can find an example here:
https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javav2/example_code/lambda/src/main/java/com/example/lambda/LambdaInvoke.java
Use Case: I need to perform an API request mapping that requires data from DynamoDB.
Desired Solution: I'd like to do this using API Gateway features if possible, which would look something like this:
An external REST API request is received by API Gateway
A Proxy Resource extracts a parameter, say accountId, from the HTTP path
A Service Integration (GetItem) reads a set of values from DynamoDB using the accountId key
The values read from the DB are input to a Request Mapper VTL template
The transformed API request is then sent to an HTTP Integration endpoint
Questions:
Is that possible to do using API Gateway out-of-the-box or is that sequence too advanced?
If it's not possible, then is a lambda the best option to do most of this work (read DB, transform request, route HTTP)?
Thanks for your help!
API Gateway will not make DB queries for you. Routing this through a Lambda function is the best option here.
I am working on a project and trying to use API Gateway to invoke a lambda function. The lambda function is used to update a DynamoDB item. The DynamoDB table is used to keep a running count of visitors to a web page. I need to create an API to invoke the lambda function but I'm not sure how to create the API. Any assistance is appreciated.
General steps would be:
Create AWS_PROXY integration between API Gateway and your Lambda function. The example of this is in the AWS tutorials: Set up Lambda proxy integrations in API Gatewa and in Tutorial: Build a REST API with HTTP proxy integration
Add/amend execution role to your function allowing it to access DynamoDB. This is exemplified in the AWS tutorial: Using AWS Lambda with Amazon DynamoDB.
Test the API. It can be done directly in API gateway console, or using external tools such as curl or Postman.
I figured out my issue. In my lamdba function, I needed to change the output to a JSON object. Once I made the change, I was able to get my API working. Here is a link to the fix.
I am trying to call sagemaker inference endpoint from api gateway with AWS Integration.I don't want to use lamdba in between of API gateway and sagemaker runtime. I followed this doc to setup api gateway method but it fails.
How can i call sagemaker inference endpoint from API gateway?
Web Browser ----> API Gateway ----> Sagemaker endpoint
API Gateway supports integration with AWS services directly (without the Lambda). You can follow the instructions at https://docs.aws.amazon.com/apigateway/latest/developerguide/getting-started-aws-proxy.html.
When you go to Step 4 in the instructions above, for the AWS Service option, you can choose 'SageMaker Runtime' to target the invoke endpoints.
API Gateway can be used to front an Amazon SageMaker inference endpoint as a REST API, by making use of an API Gateway feature called mapping templates. This feature makes it possible for the REST API to be integrated directly with an Amazon SageMaker runtime endpoint, thereby avoiding the use of any intermediate compute resource (such as AWS Lambda or Amazon ECS containers) to invoke the endpoint. The result is a solution that is simpler, faster, and cheaper to run. See this blog post for more detail on how to configure the API Gateway mapping templates against the Sagemaker runtime endpoint.
it's a long shot since it's an old question but somebody might end up here.
Reading the first section of the documentation about calling the inference endpoint in sagemaker, you'll find that you can only call it with a POST and pass your input data in the body.
https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_runtime_InvokeEndpoint.html
So it might be that you created a GET method in API Gateway and that you need to map your request parameters to a body payload or simply set up a POST method instead.