I have a deployed API Gateway Regional Enpoint in the form of:
https://some-id.execute-api.us-east-1.amazonaws.com/prod/my-path/
I know that in order to have a custom domain like www.my-domain.com resolve to https://some-id.execute-api.us-east-1.amazonaws.com/prod/my-path/ I must setup an api gateway custom domain and cloudfront distribution.
However, I'm only interested in having www.my-domain.com resolve to some-id.execute-api.us-east-1.amazonaws.com (without the path). This is so I don't need to update my clients if the deployment id changes.
I tried setting up a Route53 CNAME record with the value of some-id.execute-api.us-east-1.amazonaws.com for api.my-domain.com but it doesn't work.
I believe you just need to leave your custom domain without a base mapping. From the AWS documentation:
If you do not set any base mapping under a custom domain name, the resulting API's base URL is the same as the custom domain (e.g., https://api.example.com.) In this case, the custom domain name cannot support more than one API.
Related
I've set up an api using GCP API Gateway to map api calls to multiple Cloud Run services but now I need to point a custom domain to the API gateway. I see that there's no option to do so like in Cloud Run and I also tried setting a CNAME record pointing to the gateway's url but I didn't work.
Is their anyway I can set the domain name of the gateway?
As advised on the relevant section of the documentation:
Custom domain names are not supported for API Gateway. If you want to customize the domain name, you have to create a load balancer to use your custom domain name and then direct requests to the gateway.dev domain of your deployed API.
I'm trying to set up an API using a REGIONAL custom domain that routes HTTP requests to ALB.
The domain is registered with another DNS provider so I will not be using Route53.
Concept:
/path/to/service --> ALB (Listener: /path/*) --> ECS
I first tried with the original invoke URL https://cuxxxxmvk0.execute-api.ap-east-1.amazonaws.com/stage/path/to/service, it returns ALB context path error (It's expected because ALB gets /stage/path/to/service which doesn't hit any prefix).
Then I created a custom domain with API mapping (no base path) that maps to the stage, and try invoking it with the provided "API Gateway domain name" (The one generated by custom domain). Full URL: https://d-yjexxxds3.execute-api.ap-east-1.amazonaws.com/path/to/service
However, it returns {"message":"Not Found"}
API Gateway domain name
So my question here is:
How does the "API Gateway domain name" generated by custom domain works? Can I directly invoke the API with it?
Is it a must to CNAME it (i.e. CAME api.mydomain.com d-yjexxxds3.execute-api.ap-east-1.amazonaws.com)?
Can I make my final endpoint to be api.mydomain.com/path/to/service without the stage in path?
From the question I can see that you're trying to use CNAME to resolve to URL/some/path but that's not how it works. DNS service will only map your CNAME to some other URL only. The path (/some/path) part will remain same from your domain or API-GW URL.
Other thing to note here is that since you're not using Route53, you do not need Custom Domain Name of API-GW. Create a CNAME which is something like
example.com CNAME d-yjexxxds3.execute-api.ap-east-1.amazonaws.com
I would suggest you add /stage in your ALB prefix so that it can be accessed by API-GW and your own domain.
How does the "API Gateway domain name" generated by custom domain works? Can I directly invoke the API with it?
Yes, you can
Is it a must to CNAME it (i.e. CAME api.mydomain.com d-yjexxxds3.execute-api.ap-east-1.amazonaws.com)?
It is either CNAME (when the DNS is managed by an external provider) or it can be ALIAS (directly returning A records if you manage the DNS in Route53). Please note you need a validated certificate in the certificate manager.
Can I make my final endpoint to be api.mydomain.com/path/to/service without the stage in path?
https://d-xxxxxxds3.execute-api...
As far I know you should invoke the API by defined custom domain name (api.mydomain.com). If calling the d-.. domain will work, I'm not sure
https://api.mydomain.com/path/to/api
I'm not sure what is not working in your setup. Indeed in the custom domain mapping you can have a mapping directly to certain stage, so you may invoke the API as https://customdomain/path/to/api We have it working this way.
Long story short, your setup / idea is generally good. You may enable logging on the API Gateway or stage to find out what is not working (if the NOT FOUND is retuned by the API GW or backend ELB)
I am trying to setup a custom domain endpoint for API gateway published endpoint but not able to set.
I've followed all steps
Custom domain DNS is managed by AWS (aws cannot own this as its a .ai URL)
Created ACM Certificate for subdomain. (subdomain.host.ai)
Add Custom API in API Gateway with Mapping to particular Stage
Add A record for custom domain to point to "d-abcde12345.execute-api.us-west-2.amazonaws.com"
What might be going wrong.
When you are pointing to a DNS hostname, rather than an IP, you need a CNAME record. More importantly, when you assign a custom domain to your API Gateway, it will create a CloudFront distribution for you and gives you a CloudFront endpoint: E123CNFSOMETHING.cloudfront.net. You need to create a CNAME record in your registrar dashboard to point to this address, not the API Endpoint:
FROM TO TTL
subdomain E123CNFSOMETHING.cloudfront.net. 300
Is it possible to CNAME my own domain to AWS API gateway invoke URL?
For example, i owned example.com. I want to create (in Route53) a CNAME record from api.example.com to abcefg.execute-api.ap-southeast-1.amazonaws.com.
Using my terminal, i am able to resolve api.example.com to the invoke URL listing all 4 AWS DNS server. However, i am unable to reach my API via api.example.com but i can do so with the invoke URL without any issue.
May i know if such a CNAME can work at all or must i use a custom domain to achieve that? Thank you.
In the API Gateway console, you have to declare the custom domain that you want to use to access your API.
You will need to provide:
the protocol (HTTP or WebSocket)
the domain's name
the TLS version (leave default if not sure)
the endpoint configuration (if not sure, check this answer)
an ACM certificate (if you don't have one, you will need to create one in ACM)
The process is pretty straightforward but you will find more documentation on this process in the AWS docs if needed.
So I want something like
"example.com/helloworld" to display the Hello World message I have stored in my Lambda Function. My CFN creates a Lambda Function, and creates an API, then connects both of these services.
However, I don't know what resources to use to connect my API Gateway to a Custom DNS name like "example.com/helloworld" so I can display "Hello World" from my Lambda Function in a browser. What resources do I need here?
First step is to go to the "Custom domain names" section of your API Gateway and configure a domain for a particular API and stage. This will instruct the CloudFront distribution that serves your API (API Gateway is always served by a CloudFront in the background) to accept network requests for that domain and forward them to a particular stage (e.g. testing or production). This way you can have different domains instead of URL paths for different stages and use just the endpoint (part after the stage) of the URL.
Then you need to own a domain name (e.g. example.com) and point your domain's CNAME record to the domain that you get when you configure your API Gateway's custom domain.
If your domain is hosted on the AWS Route53 service, you can create just an ALIAS for the domain given to you by the API Gateway instead of the CNAME.
If you are asking for Cloud formation resource for connect APIGW to custom domain name ( or creating a custom domain name in APIGW ) - it is AWS::APIGateway::DomainName
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-domainname.html