user7496277
user7496277

Reputation:

How can I create a custom endpoint with amazon api gateway?

So I have setup up an AWS API Gateway in front of my RESTFUL Flask API hosted on an EC2 instance and served with gunicorn but it gave me a really ugly endpoint to hit, is there a way I could get it on to a custom url?

I've been given this url https://123x123x.execute-api.eu-west-2.amazonaws.com/myendpoint/

I'd like to have one like https://myurl.net/myendpoint

Upvotes: 1

Views: 485

Answers (1)

lasleyd
lasleyd

Reputation: 174

The short answer is:

  1. Assign Cloudfront permission to an IAM user/role in your account:
{
    "Version": "2012-10-17",
    "Statement": [
         {
            "Sid": "AllowCloudFrontUpdateDistribution",
            "Effect": "Allow",
            "Action": [
                "cloudfront:updateDistribution"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}
  1. Define an edge-optimized API endpoint mapped to your current URL https://123x123x.execute-api.eu-west-2.amazonaws.com/myendpoint/
  2. Register a certificate through AWS ACM (or if you have your own CA, create one and import it)
  3. Create a custom DNS name in Route 53 for your desired myurl.net domain
  4. Assign the new custom DNS name to an A Record Alias for the edge-optimized object e.g. a1b2c3d4e5f6.cloudfront.net

The longer answer from AWS is detailed here: https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-custom-domains.html

Note: This can also be managed to a great extent with the AWS API Gateway REST API: https://docs.aws.amazon.com/apigateway/api-reference/link-relation/domainname-create/

Upvotes: 1

Related Questions