I have a Step Function integration with one of my routes in API Gateway. My API is an HTTP API. It has the following settings:
This is successfully invoking my StepFunction but I am unable to access any of my body parameters. This route is being invoked from a front-end form which submits data. I would like to use this data for further processing in my step functions.
When I see my step function execution, the input is just {}, is there something I need to change?
In the advanced settings set a value for "Input - optional" of "$request.body"
Related
I'm using AWS API Gateway to create an api.
I have the following path for an API: /users/{id}
Is there a way to validate the existence of id in the API request made and maybe its type in API Gateway before it reaches the Lambda integration? I understand API Gateway supports validating request body, query params and headers, but I can't see any option for path parameters, does API Gateway not support that?
I'm going through the documentation and I can't seem to find something clear on that.
API Gateway can check if a path parameter exists or not. It can check if path includes any "id", but it cannot for example check what is it’s regex pattern. Such validation should be made on a client side. Either the API Gateway path follows the defined pattern, in which case it can route you to an appropriate resource, or not. It can however ensure that request parameters are present and non-blank.
The AWS documentation states that API Gateway can perform the basic validation:
API Gateway can perform the basic validation. This enables you, the
API developer, to focus on app-specific deep validation in the
backend. For the basic validation, API Gateway verifies either or both of the following conditions:
The required request parameters in the URI, query string, and headers of an incoming request are included and non-blank.
The applicable request payload adheres to the configured JSON schema request model of the method.
To enable basic validation, you specify validation rules in a request validator, add the validator to the API's map of request validators, and assign the validator to individual API methods.
Note that comparison with JSON schema request model refers to the request payload, and not to request parameters. In the documentation you can find guidance on how to enable request validation in API Gateway:
by importing OpenAPI
definition
using the API Gateway REST
API
using AWS
console
Also, follow this blog post which explains how to set up request parameters validation. Mind however, that the basic validation ensures that the request parameters are present and non-blank. More advanced validation, like checking regex pattern or type, is not possible to my knowledge.
So I am trying trying to execute a PutItem request from my AWS API Gateway. I am trying to do this by using the path /storeid/{username}/{password}. I have done the mapping as json and the test within the API works perfectly and I see my data show up in my DynamoDB table but when I deploy the API and try to invoke this request I receive the following response: {"message":"Missing Authentication Token"}. This request does not have any authorization or API key requirement. Why does the test work but not the url when invoked.
ps-yes I entered the correct url
Please help!
A few things to check
Verify that Authorization is set to None (i.e. not IAM) in your Method request settings.
Verify that you deployed your API changes to your stage. Using the console, click Actions -> Deploy API.
Once deployed the URL to use should be displayed when you select the Stage that you deployed to. Verify you are using the correct URL.
Also, side note, it is a really bad idea to be putting passwords in your URL path or query parameters. Consider doing sending the data in the request body as a POST and doing something like HTTPS and hashing to protect the password.
I am new to AWS. I am asked to use the services that is written in java and already exist in java EC2 to serve the UI. I need to use API gateway to call the services so the UI will first call the API gate way and then API gate way will call my service. Also I know that in Select Integration Request if I choose http proxy and add the url of my services on Ec2 I can achieve this. However the problem is that I have a service like this:
http://domainname/article/{id}
As you can see the id is a variable and the above service should be called via API Gateway so API gate way should be able to pass the id to the service url. Lets say the following is the url of API gateway:
https://my-api-id.execute-api.region-id.amazonaws.com/stage-name/article?id=1
How can I handle the above scenario? is it possible to do that?
While you can use a Lambda function for this, you can also do it directly from API Gateway using basic request mapping.
Define your API in API Gateway with a resource having path /article
Add a GET method.
In the Method Execution pane, choose Method Request.
Expand "URL Query String Parameters"
Hit "Add query string"
Type id as the name and hit the checkbox on the right to save
Go back to the Method Execution pane, choose Integration Request.
Edit your endpoint URL to add the path parameter, if you have not already done so.
The URL should be: http://domainname/article/{id}
Choose the arrow next to "URL Path Parameters" to expand that section.
Click "Add path".
Enter id as the name
Under "Mapped from" enter: method.request.querystring.id
Click the check box on the right to save.
Go back to Method Execution and click Test.
Add an id value under query strings and click test.
There are some similar examples in the documentation here
I would suggest using Lambda to re-assemble the request. API Gateway will invoke the Lambda function that would receive the request
http://domainname/article/1
and will perform an HTTP request to your service
https://my-api-id.execute-api.region-id.amazonaws.com/stage-name/article?id=1
I'm attempting to port an existing API to AWS API Gateway.
I've got everything working, in that using the 'test' GUI for each of my endpoints successfully hits my configured EC2 instances.
I used the swagger import facility to automatically map all possible endpoints and their associated URL parameters.
What I've noticed is that when the request hits my API (EC2 instance) the URL has been transformed slightly. The URL parameter order has changed.
Regardless of the parameter order that I paste into the test GUI, the order of the parameters when they hit my API has been changed to the order that they are specified within the 'Method Request' GUI screen.
Does anyone know how to prevent this from happening?
There is no way to achieve this using a lambda 'custom authoriser'
I was trying to use a Lambda function as a custom authoriser which then proxies through to our HTTP API. The only data available to the custom authoriser is the 'Token' in the header (can be named anything you want - setup via API Gateway GUI). You can of course populate this with whatever values you want and one suggestion was to put the param order in this header and then perform some logic at this lambda level, however that meant modifying our API callers which wasn't desirable.
You do have access to the 'transformed' URL (e.g. 'https://df64sxl1.execute-api.us-east-2.amazonaws.com/prod/myEndpoint) but this isn't very useful.
If you are able to utilise lambda integration (instead of custom authorisation) you might be able to achieve what you by using payload-template mappings as these provide a way of accessing the raw request.
My scenario is when my Lambda function's Api endpoint is hit, with a post variable, i want my Lambda to invoke a database connection and get some results.
So the first step is to create an API Gateway endpoint and I have problem creating the POST method with parameters
Here is what i did till now:
Created a API Endpoint for my Lambda Function.
When i go into the POST Method in Lambda's API endpoint section, i am taken to this screen
When i Test the function from the AWS Console,
and response is as follows in the console
How do i create parameters for the api here? and how do i test it? I have my lambda function ready, that takes in a String as input and returns a String as response.
Can someone guide me for the next steps..
You can check the Create and Test a POST Method
you do not mention the parameters in the lambda definition, the parameter will be taken from the request directly (so in future if you change your lambda code to take new parameters, you dont need to change the configuration
To test :
In the Method Execution pane, in the Client box, and then choose TEST.
Expand Request Body, and type the following:
{
"name": "User" <or any other parameter that you expect>
}
Choose Test. If successful, Response Body will display the reply from
your lambda execution
For example here an example post api I had
so again for POST API you dont define the parameters
If you were doing GET API you would define the query parameters
Great step by step explanation of Serverless API on AWS: Serverless API on AWS in 10 minutes
The answer by Frederic is very good, I'll just leave another example in the docs -> http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html
Further down on that page is an example for Param Mapping which will proxy any incoming parameters to Lambda. You still need to explicitly state any incoming parameters that you expect clients to send in the Method Request.