API Gateway REST API integration request path rewriting with multiple path parts - amazon-web-services

I have an API Gateway REST API with an integration to S3. We don't want to directly expose the buckets and object keys so there is an authorizer that is taking a path parameter and returning an object key. This object key may contain a number of path parameters, eg, path/to/object. I want to be able to rewrite the integration path to include this.
When I try using a path variable the value is replaced but it's URL encoded, ie, path%2Fto%2Fobject so of course the S3 request fails. I don't see any way of replacing the path variable with a value that contains multiple path parameters. I've also tried the same thing using #context.requestOverride.path.XXX in a mapping template and it also ends up URL encoded. I've tried using $utils.urlDecode() but again the result is encoded.
Is there any way to replace a path variable with multiple path segments? Otherwise, is there a way to completely replace the path in a mapping template (not just specific path variables)? Or is there another way to achieve this eg can the object key be passed in a header?

Related

Using Range with presigned url AWS S3

When I create a presigned url - it generates a X-Amz-Signature.
Using this signature in the query param along with the Range query param causes the signatur to then be invalid. Is there anyway to get around this?
The request signature we calculated does not match the signature you provided. Check your key and signing method.
The signature will no longer be valid if you change the URL's query parameters or headers after creating it, which will lead to the error
The request signature we calculated does not match the signature you provided. Check your key and signing method.
Your question doesn't make clear which query parameter you are updating, however, it's possible that you are doing so after creating the pre-signed URL if you are changing the "Range" query parameter. If this is the case, the changed Range header would render the signature invalid because it is used in the calculation of the signature.
Solution : Create a fresh pre-signed URL with the amended Range header to get around this. If the Range header needs to be changed frequently, write a function that produces a fresh pre-signed URL each time the Range header is changed.

How can I pass tenant value in the URL via Integration Studio?

I have a multi tenant API and I am trying to RESTIFY it using wso2. I am trying a way to pass the tenant value in the url.
localhost:8290//tenant/api/...
https://tenant.xyz.com/api/...
I tried İntegration studio and i managed to pass a literal tenant value in http endpoint by creating a property named {uri.var.tenant} and setting it to tenant name. However, I don't know how can I take the tenant name from here
localhost:8290//tenant/api
and pass it here.
https://tenant.xyz.com/api/
I also tried using the APIM publisher page with no success.
As I see, there are 2 parts for your question.
How to parameterize the backend URL.
How to read the path parameter from the fronting API that is being called.
For the first one, the method you have followed is correct and an example can be found at https://apim.docs.wso2.com/en/latest/integrate/examples/endpoint_examples/using-http-endpoints/#example-1-populating-an-http-endpoint-during-mediation . What's remaining is to read the path parameter and to populating {uri.var.tenant} which is the second point.
For the second point, you can create and API definition with the URL templated. See the property URI Template at https://apim.docs.wso2.com/en/latest/reference/synapse-properties/rest-api-properties/ you can find an example of the usage at https://apim.docs.wso2.com/en/latest/integrate/examples/rest_api_examples/setting-query-params-outgoing-messages/#reading-a-query-or-path-parameter

Pass dynamic path via API-Gateway to AWS-Lambda

I'm running a Flask-application on AWS-Lambda based on this tutorial:
https://andrewgriffithsonline.com/blog/180412-deploy-flask-api-any-serverless-cloud-platform/#create-flask-app
My problem now is that this setup works absolutely fine for the defined home-path ("/"), but whenever I call e.g. "/user/7" the API-Gatway returns 403, since it doesn't know the route, although it is defined in the Flask-Lambda.
Is there a possibility to setup API-Gateway in a way to pass the whole request through to the Lambda, regardless of whatever path the request has?
You can use the {proxy+} path to act as a catch all for API Gateway.
By creating the proxy resource anything that matches the prefix will automatically use that resource, if you add it to the root resource then it will process all other requests that do not match a specific URL pattern.
You could also use variables in your path resource names, for your user method for example the path would end up being /user/{userId}. This is the preferable solution as it is still being specific to the request type.
More information is available here.

API Gateway Custom Domain - having both empty base path mapping to stages and a static html page on the empty base path

I have an AWS API Gateway set up with a custom domain name one the format api.example.com. I have a api.example.com/prod stage and a api.example.com/dev stage, but I would also like to be able to modify the response returned on api.example.com.
What I want is very similar to how the GitHub api behaves. Where https://api.github.com/v2 access version 2 of the api, and https://api.github.com/v3 access version 3, but https://api.github.com gives a custom response.
In my case I would like to have a small static html page on api.example.com, but a custom json response (like on api.github.com) is fine, anything more helpful than {"message":"Forbidden"} would do.
I know I set up base path mappings to the dev and prod stages in the custom domain window (as my partially redacted settings below), but I would like to add a empty path as well, and have that point to another API with just a GET method on the root resource that returns a small static html page. API Gateway does not allow combining an empty base path mapping with non-empty base path mappings (for a good reason I assume), but it feel there should be some way to achieve what I am trying to set up.
Anyone who knows a way to achieve this using AWS API Gateway?

How to create URL with path parameters inside API Gateway

I want to create a path as follows in the API Gateway:-
/users/{userId}/photos/{photoId}.
A clever guy may say why can't you go for /users/photos/{userId}/{photoId}. Well I can't club many path parameters under the same URL.
How can I create a precise URL path with API Gateway.
Refer to the section with the following heading in this link.
Integration 3: Create a GET Method with Path Parameters to Call the Lambda Function