Routing message from AWS API Gateway to SQS regarding URL path - aws-api-gateway

I need to route a message from API Gateway to a specific queue regarding URL Path.
By example:
/queues/{queueId} -> API GW routes /queues/queue1 URL to SQS queue1
Is it possible to do it "simply" only with API GW config or do I need to use a lambda to make the routing to the right queue ? or any other solution ?

It is possible to do that.
While configuring integration on Path Override you need define it like 12345678/{queueId} (12345678 is your account id).
Then you need to define URL PATH Parameters
Name queueId, Mapped from method.request.path.queueId
Expand HTTP headers add new Header with Name Content-Type, Mapped from as 'application/x-www-form-urlencoded'
Add a Mapping Templates as Content-Type application/json and template body as Action=SendMessage&MessageBody=$input.body

Related

Add dynamic headers to NestJS HTTPService

Let's say we have a GraphQL NestJS application which acts as a proxy between a client and a REST API server. It's got 3 layers:
Resolver
Services (which kinda have the business logic and stuff)
Something extending HTTPService with added functionalities
We want to add dynamic headers to NestJS outgoing requests to REST API server, which uses axios. The headers are based on:
User: We can read user with the help of User decorator in resolver and pass it down to services, or read it from the GraphQL context as far as I know.
Routes: Different endpoints may require different headers. I think we can specify the types of header that should be added because of a specific rout in the service, but this does not look so scalable... . Or maybe we can store an object of the current paths, that we make requests to. Intercept outgoing requests and use RegExp to determine which path is the request is being sent to (i.e. user/3 would translate to user/:id, which we can add proper headers knowing that).
[
{
path: 'user/:id',
...
},
{
path: 'user/:id/image',
...
}
]
So my question is how can we add headers to outgoing requests from a NestJS application to some endpoints based on the path(url of the axios request) and the current user. Is matching a url with some RegExps while intercepting an outgoing request expensive?
Had the same problem and solve it by using Injection Scopes in Nest GraphQL
https://docs.nestjs.com/fundamentals/injection-scopes#request-provider
However, there's a caveat in terms of performance.

Can we parameterize the url of HTTP POST Request while creating Logic apps in devops

Hi I am new to LogicApps and want to understand if it is possible that while creating/designing a logic app to send email, can we parameterize the HTTP Post Method URL, that is auto-generated?
If you're looking for a possibility to accept parameters in the endpoint URL, then: yes, you can.
Taken from Accept parameters in endpoint URL:
When you want your endpoint URL to accept parameters, specify the relative path in your trigger. You also need to explicitly set the method that your HTTP request expects.

API Gateway HTTP integration, how do I pass the authorization header?

I'm in "Integration Request". I've set HTTP integration type and the Endpoint URL.
Below, I see "HTTP Headers, but if I try to add an header, there is a strange "mapped from" value I don't understand.
Setting an HTTP Proxy integration add a Mapping template I also don't understand.
I just need to pass the Authorization:xxxx and X-Auth-Username:xxxxx from the original request to the endpoint
Can't find an easy way...
I set HTTP proxy integration and added in the HTTP Headers (and deployed):
method.request.header.Authorization
method.request.header.X-Auth-Username
I also added as required Authoriaxtion and X-Auth-Username in Method request header as required.
But I get an error upon calling the api:
Authorization header requires 'Credential' parameter.
Authorization header requires 'Signature' parameter.
Authorization header requires 'SignedHeaders' parameter.
Authorization header requires existence of either a 'X-Amz-Date' or a 'Date' header
Hmmm maybe it's a "naming" problem?
So I changed "authorization" with MyAuthentication in the method request, and after in the integration Header, I mapped Authorization to
method.request.header.MyAuthentication
Now if I call my api with MyAuthorization in the header, I get "Missing Authentication Token", without hitting the api server
Click on 'Method Request' , expand 'HTTP Request Headers' and add a header Authorization . Now go back and click on 'Integration Request' , expand 'HTTP Headers' and add Header Name Authorization and 'Mapped from' method.request.header.Authorization . Basically for any header XYZ on 'Method Request' tab should have corresponding mapping on 'Integration Request' method.request.header.XYZ .
To Correctly use aws API Gateway as a pure http proxy and make it pass the Authorization header as-is to your backend API, you need to do two things:
In the Method Request: Make sure to add the Authorization header to the Http Request Headers section.
With this, AWS does not assume that the Authorization header is of your own implementation and the gateway does not expect it to contain AWS own format of multiple parameters such as SignedHeaders, Signature, X-Amz-Date , etc..
2. In the Integration Request: Make sure to select the Use HTTP Proxy Integration.
This makes sure that the request is being sent to the target as-is and thus the Authorization header not to be consumed and discarded as part of AWS own SigV4 authorization.
The following was correct...I was calling the original api path instead of te api gateway path....
I set HTTP proxy integration and added in the HTTP Headers (and deployed):
method.request.header.Authorization
method.request.header.X-Auth-Username

AWS API Gateway: Pass Referrer URL

Is it possible for requests to the API-Gateway to pass the referrer URL to Lambda? For example, I'd love to let my lambda functions know if a request comes from the domain "good.com" vs. "bad.com".
I'm familiar with the list of supported $context Variables and I know a referrer url is not in there. I'm wondering if there is another way. If it is possible, what steps do I need to take?
Here's how to do it.
As it turns out, the mapping template allows you to map HTTP headers, not just the list of supported variables in the documentation.
The HTTP header that contains the referrer domain is called "Origin". The header that contains the referer page URL is called "Referer".
So, for example, you can put this in your mapping template and it will grab the associated header information:
{
"origin" : "$input.params('origin')",
"referer" : "$input.params('referer')"
}
Origin grabs example.com. Referer grabs example.com/pagename
It's an HTTP header, so if you are mapping HTTP headers in the template it will be passed to the Lambda function. Look at this answer for an example of how to map HTTP headers in the request template.

Restful web service GET request parameters

I'm using fiddler to test a Web API service I'm writing.
I know I can pass parameters to a RESTful web service in the querystring with a request like -
www.example.com/api/Book?Id=123&category=fiction.
Are there other ways of passing the parameters to the service, while still using a GET.
There are many parts of the HTTP request which you can use to pass parameters, namely the URI, headers and body. GET requests don't have bodies (some frameworks actually allow that, but they're not common so for all purposes, let's just assume that they can't), so you're limited to the headers and the URI.
In the URI you can pass parameters in different places:
Query string (as you're already doing)
Ex.: www.example.com/api/Book?Id=123&category=fiction
Request path
Many frameworks will allow you to get parameters to your actions from paths in the request URI. With ASP.NET Web API you'd typically do that using routing
Ex.: www.example.com/api/Book/fiction/123
In the fragment, or the part of the URI after the # character. See the URI RFC, section 3.5.
Ex.: www.example.com/api/Book?Id=123&category=fiction#somethingElse
You can also pass paramters in the HTTP request headers. One parameter which is honored by the ASP.NET Web API is the Accept header, which is used when doing content negotiation. You can also expect custom parameters from those headers, and read them in your actions (or even have value providers which will read them and map them to the parameters in the methods themselves).