I keep seeing comments on how to do URI versioning in API Gateway, and these all say the same thing,
Do not create the version path (/v1) as a resource in your API. Instead, simply call you API "Names V1" and start creating the resources (/names). When you want to make a breaking change and create a new version of the API, we recommend you create an entirely new API called "Names V2". Once again, simply create your resources without the version path.
To bring the two APIs together, you can use custom domain names. A custom domain name in API Gateway includes both a fully qualified domain name and a base path. Create two custom domain names:
myapi.com/v1 -> points to the prod stage of the Names V1 API
myapi.com/v2 -> points to the prod stage of the Names V2 API
However, when you try to create a Custom Domain Name with a "/" in it, API Gateway responds with "Invalid Domain Name". So if you try to do it on the mapping, you get something similar mentioning the special characters you can use, and "/" is not one of them. So your only option is to use the Stage variables which these posts mention the challenges of doing it that way.
Additionally, if you just make it "v1" with no slash, then we are unable to have a custom domain like "api.whatever.com". Then makes the custom domain be specific to an API area that needs to be versioned. Ex. "stores.whatever.com". This causes each API to have their own subdomain.
URI-based Versioning for AWS API Gateway
API Versioning with AWS API Gateway
Sorry for asking a new question, but I'm not allowed to add a comment on the posts.
I'm not sure I understand the request here, let me try to clarify. When a request comes in to your custom domain name api.whatever.com, API Gateway needs to determine where to send the request. API Gateway will look at the path and then determine if there are any API:STAGE mappings for that path. You can configure an empty base path mapping on a custom domain name, but then all requests without a path to that custom domain name will be routed to the API:STAGE mapping. It seems like you're trying to route requests to either api.whatever.com or stores.whatever.com, you can do this with two custom domain names each with their own empty base path mapping. For example:
Custom domain name1: api.whatever.com
api-id: 12345
stage: Live
api-mapping-key: NULL
Custom domain name2: stores.whatever.com
api-id: 67890
stage: Beta
api-mapping-key: NULL
Your clients will have to specify the proper domain name when calling your APIs.
Related
I would like to know if is possible to have one website hosted on aws for example www.myname.com but then to have the possibility to map different domains to different paths. for example:
map domain www.hellogeorge.com (just an example) to www.myname.com/george
then another person to map his domain www.otherdomainchristian.com to www.myname.com/christian
i want to say that the www.myname.com/name is an api end point which generates an html webpage depending on the specific parameter used.
If such tecnologies are present may somebody guide me what to learn, study?
Thank u very much.
Well, it's pretty simple to do. You can use S3 bucket static web hosting to do the redirection. For example,
map domain www.hellogeorge.com (just an example) to www.myname.com/george
Create an S3 bucket called www.hellogeorge.com and then set redirection domain/path to www.myname.com/george
then another person to map his domain www.otherdomainchristian.com to www.myname.com/christian
Create another S3 bucket called www.otherdomainchristian.com and then set redirection domain/path to www.myname.com/christian
Now, when a user visits www.hellogeorge.com or www.otherdomainchristian.com, he/she will get a 301 redirection to the corresponding destination.
Next, you can use Amazon API Gateway to generate dynamic response depending on the request parameter.
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?
I'm developing an Angular Universal serverless app in AWS Lambda/Api gateway. The app works perfectly using the standard api url ( {api-id}.execute-api.{region}.amazonaws.com/{stage}/) but now I'm trying to deploy it in a human-readable url using Api Gateway's Custom domain names.
For that I followed the docs and troubleshooted using other stackoverflow's questions, but now I'm faced with a problem and can't find another question that looks like my problem.
I have already setup the API, the custom domain name (which created a cloudfront distribution) and a Route53 A-type ALIAS routing to this new cloudfront distribution and the routing kind of works.
The problem I'm facing is that when I'm using the new domain name, the angular app cant find assets like CSS, Icons,etc. All of them works fine using the standard api url but not with the custom.
To do some debugging I configured Api Gateway to log requests to CloudWatch, and I can see that when I'm using the standard url, the resource path log is like this:
HTTP Method: GET, Resource Path: /main.4d57a71fd195330e8ee9.js
But when I use the custom URL the same log is like this:
HTTP Method: GET, Resource Path: /development/main.4d57a71fd195330e8ee9.js
I'm guessing it has something to do with the base URL in the custom domain name configuration of Api Gateway, I tried changing it to everything I could think of but nothing fixed it.
Here is a screenshot of my Api Gateway configuration.
Api gateway - Custom Domain Names configuration
Tell me if you need anything more and sorry if bad english.
Thanks in advance.
EDIT: I should make clear that I'm trying to point to the "development" stage of my api
I believe you simply need to reconfigure your custom domain. It should be sufficient for you to change the following;
In "Base Path Mappings" section change Path from "/development" to just "/"
I had similar problem. The only workaround for me is to set baseHref to "/" in environment.serverless.ts and have one single mapping in custom domain name from "/" to "{YOUR-API}:production".
This breaks direct url access to the API but access via custom domain name works fine.
I just got my custom domain name setup via AWS API Gateway, and now I have several domain names all routing to one lambda function. which just serves a webpage.
The setup looks like this:
And I have several of these with different domains that I want all to serve the same content.
Now, I'd like to add another path like /getdata or something which will just serve some data from a database instead of serving static HTML.
But when I try to add another path I get this error:
Error
Only one base path mapping is allowed if the base path is empty.
How can I have a single domain with multiple paths then?
I tried just using the wildcard path: *, and that works for multiple paths like /test or /getdata, but it doesn't work with just the domain name, and I can't tell every single user to make sure to type something in like /home everytime
Ahh I figured it out!
So, unfortunately, the page that shows you the custom domains is not where you need to be making your routes.
The correct procedure is to create an API (or use an existing API, and modify the resources) and give it a proxy resource, and a plain GET method that originates from the root path.
First, go to your API GateWay console, and create a new API.
Then once you give it a name, and choose the type (regional, or edge), it will show you the resources page
Here, you will do 2 things: Create a catch all proxy resource, and also a get resource to the root path.
Step 1: Make a catch all proxy resource:
Click Actions, and choose Create Resource
On the wizard, click Configure as proxy, and give it a name. Leave the resource path as it is. Then click create resource. The {proxy+} is notation that tells AWS that this resource should accept any path that has anything after the /. This means /test will work as well as /test/1/2/3/etc. However just / alone will not work!
Next, it will take you to this screen where you choose your integration type. We want lambda, which is the default. Make sure to select the correct region, for me the default was the right one. Then start typing in your lambda function name, and it should dynamically pop up a list of your lambda functions. select the one that you want for your application. If that doesn't work, you can copy and paste your lambda ARN from the lambda function console. Click Save.
Step 2: Make a get resource for the root path
Click the root slash at the top, right under where it says resources. Then click actions, and choose Create Method. It will pop up a little selection thing under the root slash, and there you should select GET, and then click the little checkmark.
Here, make sure to check Use Lambda Proxy Integration, and then the rest of this form should be the same as the last one you did. Just select your region, and your lambda function, and click Save.
Step 3: Deploy
Once that's done, go to actions, and choose Deploy API, give it a name for a stage, and some description, and then you are ready to attach this API to your custom domain.
Step 4: Attach
On the left tab scroll down to where it says Custom Domain Names, and create a new domain name (or attach it to an existing one if you have it)
Enter your domain name, and choose regional or edge. Then choose your certificate (there are many good guides for how to make a certificate through AWS)
Once you click save, it will look something like this:
Click Show Base Path Mappings, and then Edit.
In the path field just leave a slash, in the Destination field, choose from the dropdown the API that you just deployed. And on the right, select the stage that you made when you deployed your API.
Lastly, it will sit at initializing for a while, so while you wait for that, remember that you need to make a route53 record set for this domain, and map it to the cloudfront target URL that the API GateWay gave us. This target url looks like: www.u10dsa3s5iovdk.cloudfront.net. Copy that, and go to Route 53, Choose the hosted zone for your domain. Create a record set, and give it the same name as the domain you just created, so if you made www.example.com, in the name field of Route 53 you need to type in www. or if you made test.example.com you need to type in test. Then choose Alias: Yes, and for the Alias Target, paste in the cloudfront url from API GateWay.
When the custom domain name is done initializing, you can make calls to www.example.com as well as www.example.com/anything/else/you/want/to/put/here
Hope this helps anyone who was stuck as long as I was. Please let me know if there's anything I missed, or if something is inaccurate.
In this case you need to configure a path different to "/" for each api you need to serve through custom domain. AWS Api Gateway don't let you to serve several api into the same custom domain if you serve at least one api with no base path.
I am aware that many similar questions have been posted and answered here but none of them is quite the same with what I am experiencing.
I have a Lambda function that handles incoming requests (GET and POST). I also set up an api gateway as public facing endpoint. Additionally, I set up custom domain following Set up Custom Domain Name for API Host Name
The testing call works in both of lambda and api gateway console. Everything also works using the invoke URL but not with the custom domain I've set up.
Here are some more details:
Invoke URL (Works) :
https://{api gateway id}.execute-api.us-west-2.amazonaws.com/prod/endpoint
Custom domain endpint (Doesn't work):
https://api.{my domain}.com/endpoint
Base Path Mapping:
/endpoint endpoint:prod
All Method Auth:
Authorization None
API Key Not required
Route53:
A record as alias that points api.{my domain}.com to the cloudfront distribution domain name as alias target.
I'd really appreciate if anyone knows what's going out here.
I had met the same question several years ago and solved it by removing the 'stage' name from the URL.
the URL of gateway API seems like the following:
https://{id}.execute-api.{region}.amazonaws.com/{stage}/todos
if you have routed a custom domain https://api.xxx.com to gateway API {apiName}:{stage}, it seems like the following:
https://api.xxx.com
path: /
target: {apiName}:{stage}
Finally, the correct way to call it is to remove the stage name:
// **remove stage name!!!!**
// Right
https://api.xxx.com/todos
// Wrong
https://api.xxx.com/{stage}/todos
I found the issue is misunderstanding of how base path mapping works.
All my configurations are correct.
My API resource is not under / but under /endpoint
To use the custom domain, instead of visiting https://api.{my domain}.com/endpoint, it needs to go to https://api.{my domain}.com/endpoint/endpoint
Of course this is silly and redundant.
I have two options. I either set up the base path mapping to / instead of /endpoint or I can just user the API resource / instead of /endpoint.
I go with the latter because if base path mapping is set to /, my api.{my domain}.com will only be able to host just one API (I can still use resources under the same API, but why wasting the extra layer of abstraction?).
This seems dump but I am still glad I figured it out.
Another reason for this can be that your user, although admin, does not have a bloody CloudFrontFullAccess permissions! I just spent a couple of hours on it as I relied on serverless to do it for me and it worked perfectly on another project with different credentials, though. So double check the article! https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-custom-domains.html
Step 1: Map the A record from subdomain.yourdomain.com to API Custom domain/API Gateway domain name(API Gateway -> Custom domain names -> tab Configuration/Endpoint Configuration).
Step 2: From API Gateway/ API Custom domain - add the api mapping. Leave "path" empty.
End point format:
Original endpoint: https://{api gateway id}.execute-api.us-west-2.amazonaws.com/prod/endpoint
Endpoint with API custom domain: https://api.yourdomain.com/**endpoint**