In API Gateway I have a GET endpoint like following (with some request headers too)
http://awesomedomain/v1/myspecialkey/find?a=b
Is there a way the Lambda (Authorizer) code can read "myspecialkey"?
Thanks in advance
Yes it is possible, when you are building lambda authorizer you can choose Lambda Payload Type to be Request.
Assuming that you have named your first lambda parameter events, then inside of the lambda, you will have access to your parameter values via
event.pathParameters
as well as access to your query string via
event.queryStringParameters
And other request information if needed, such as authorization token which you can extract from event.headers.
the above code uses NodeJs syntax, the same logic holds true for Java but you will need to modify it according to Java syntax
Related
I have a basic service in Java, for example:
public interface FolderService {
void deleteFolder(String path);
void createFolder(String path, String folderName);
void moveFolder(String oldPath, String newPath);
}
which has multiple implementations. How can I map this service on AWS Lambda and API Gateway ?
I am expecting the API to have the format
POST {some_url}/folderService/createFolder
or
GET {some_url}/folderService/createFolder?path=/home/user&folderName=test
First, design your API mapping each HTTP method to a Java method.
DELETE /{path}
POST /{path}/{folderName}
PUT /{oldPath}?to={newPath} or PUT /{newPath}?from={oldPath}
Second, create the API Gateway Mapping. Each HTTP method has its own mapping. Define a constant value with the name of the method. Ex.
"action" : "deleteFolder"
Create three lambda functions. Each function, in the function handler, reads the "action" attribute and call the correct method.
or
Create one single lambda function that reads the action and calls the respective Java method.
API Gateway Mapping Template
Lambda Function Handler (Java)
You already have experience with AWS Lambda? The mapping part can be tricky. Feel free to ask for more details.
I have one webservice which can take multiple content-types in request
text/plain
application/json
Now, client can send any of them either json or text.
I have two options available on server
I can create separate apis for different content types
I can parse request data and check if its json or text?
What is better approach here?Is there a design pattern suited for this need?
Note: Management prefer to have one api which can support multiple content-types.
The client must include a Content-Type header indicating the format of the entity they are sending to the server. If the server does not support the format which a client has sent, the expected response is 415 Unsupported Media Type.
I would go with option 1 and have the common logic placed in a seperate method. That way you let the API check and parse the input data for you.
In http you use the "accept"- header to define what type you expect the response to be. The server delivers the content as defined in accept header, the default if it's not set or 406 - "Not acceptable" if the type is not supported
https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
One way would be to use #Path annotations more thoroughly-
The #javax.ws.rs.Path annotation must exist on either the class and/or a resource method. If it exists on both the class and method, the relative path to the resource method is a concatenation of the class and method.
See this link https://docs.jboss.org/resteasy/docs/1.1.GA/userguide/html/Using__Path_and__GET___POST__etc..html
URL: /test/{userName}
In AWS Lambda function, How can I get the {username} path parameter value.
I am calling lambda function through AWS API gaetway.
If you are using AWS integration type:
Use a mapping template to send $input.params('username') property in the request body to your Lambda function.
If you are using AWS_PROXY integration type:
You can access the path parameters via the "pathParameters" property of the incoming event.
I have a problem with my JMeter code, particularly with type of variables that are returned by JDBC Request.
This because then i have to make a json with this variables and therefore is most important the type of them otherwise my rest web service returns error.
I made this code:
The problem is on global_state variable because jdbc request save it as a string but the value is a float in my rest service.
What is the solution?
I also tried to use Beanshell PreProcessor to convert it without any result.
Thanks
I think that it resolved, or won't fail during the http request, with this code:
"grid_voltage": "${grid_voltage_1}"
What is the difference between passing query params as /cars/id/toyota vs /cars?id=toyota in a webservice?
Is one REST vs other web service type?
Passing parameter in Rest service in the form of Url or query string, both have different significance.
In simple words
/cars/id/toyota in this toyta is variable and your service expecting something after id/{variablename} otherwise it gives an error (endpoint not found). So in this case your variable became mandatory.
/cars?id=toyota in this case your query string (Id) becomes optional.
So use query string whenever you want to make that variable optional. :)
Nothing, obviously–it all depends on how the consuming service expects to retrieve parameters.
It depends on the receiving party (your web server and the framework you use on that web-service). Both or neither could conceivably be REST web-services, depending on your implementation.
Conceptually, the difference lies in the path from the web-server root (/) and parameters:
/cars/id/toyota is a URL to path /cars/id/toyota without parameters
/cars?id=toyota is a URL to path /cars with parameter named id with value toyota