func (c *Client) GetRoute(apiGatewayID string, endpoint string) (*apigatewayv2.Route, error) {
	var nextToken *string
	for {
		routes, err := c.APIGatewayV2().GetRoutes(&apigatewayv2.GetRoutesInput{
			ApiId:     &apiGatewayID,
			NextToken: nextToken,
		})
		if err != nil {
			return nil, errors.Wrap(err, "failed to get api gateway routes for api gateway "+apiGatewayID)
		}
		for _, route := range routes.Items {
			if *route.RouteKey == "ANY "+endpoint {
				return route, nil
			}
		}
		nextToken = routes.NextToken
		if nextToken == nil {
			break
		}
	}
	return nil, nil
}
GetRoute retrieves the route matching an endpoint, or nil if unable to find it
package aws
import (
	"fmt"
	"strings"
	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/service/apigatewayv2"
	"github.com/cortexlabs/cortex/pkg/lib/errors"
)
func (c *Client) CreateAPIGateway(name string, tags map[string]string) (string, error) {
	createAPIResponse, err := c.APIGatewayV2().CreateApi(&apigatewayv2.CreateApiInput{
		Name:         aws.String(name),
		ProtocolType: aws.String(apigatewayv2.ProtocolTypeHttp),
		Tags:         aws.StringMap(tags),
	})
	if err != nil {
		return "", errors.Wrap(err, "failed to create api gateway")
	}
	if createAPIResponse.ApiId == nil {
		return "", errors.ErrorUnexpected("failed to create api gateway")
	}
	_, err = c.APIGatewayV2().CreateStage(&apigatewayv2.CreateStageInput{
		ApiId:      createAPIResponse.ApiId,
		AutoDeploy: aws.Bool(true),
		StageName:  aws.String("$default"),
		Tags:       aws.StringMap(tags),
	})
	if err != nil {
		c.DeleteAPIGateway(*createAPIResponse.ApiId)  
		return "", errors.Wrap(err, "failed to create $default api gateway stage")
	}
	return *createAPIResponse.ApiId, nil
}
func (c *Client) GetVPCLinkByTag(tagName string, tagValue string) (*apigatewayv2.VpcLink, error) {
	var nextToken *string
	for {
		vpcLinks, err := c.APIGatewayV2().GetVpcLinks(&apigatewayv2.GetVpcLinksInput{
			NextToken: nextToken,
		})
		if err != nil {
			return nil, errors.Wrap(err, "failed to get vpc links")
		}
		for _, vpcLink := range vpcLinks.Items {
			for tag, value := range vpcLink.Tags {
				if tag == tagName && *value == tagValue {
					return vpcLink, nil
				}
			}
		}
		nextToken = vpcLinks.NextToken
		if nextToken == nil {
			break
		}
	}
	return nil, nil
}
func (c *Client) GetAPIGatewayByTag(tagName string, tagValue string) (*apigatewayv2.Api, error) {
	var nextToken *string
	for {
		apis, err := c.APIGatewayV2().GetApis(&apigatewayv2.GetApisInput{
			NextToken: nextToken,
		})
		if err != nil {
			return nil, errors.Wrap(err, "failed to get api gateways")
		}
		for _, api := range apis.Items {
			for tag, value := range api.Tags {
				if tag == tagName && *value == tagValue {
					return api, nil
				}
			}
		}
		nextToken = apis.NextToken
		if nextToken == nil {
			break
		}
	}
	return nil, nil
}
func (c *Client) DeleteVPCLinkByTag(tagName string, tagValue string) (*apigatewayv2.VpcLink, error) {
	vpcLink, err := c.GetVPCLinkByTag(tagName, tagValue)
	if err != nil {
		return nil, err
	} else if vpcLink == nil {
		return nil, nil
	}
	_, err = c.APIGatewayV2().DeleteVpcLink(&apigatewayv2.DeleteVpcLinkInput{
		VpcLinkId: vpcLink.VpcLinkId,
	})
	if err != nil {
		return nil, errors.Wrap(err, "failed to delete vpc link "+*vpcLink.VpcLinkId)
	}
	return vpcLink, nil
}
func (c *Client) DeleteAPIGatewayByTag(tagName string, tagValue string) (*apigatewayv2.Api, error) {
	apiGateway, err := c.GetAPIGatewayByTag(tagName, tagValue)
	if err != nil {
		return nil, err
	} else if apiGateway == nil {
		return nil, nil
	}
	err = c.DeleteAPIGateway(*apiGateway.ApiId)
	if err != nil {
		return nil, err
	}
	return apiGateway, nil
}
func (c *Client) DeleteAPIGateway(apiGatewayID string) error {
	err := c.DeleteAPIGatewayMappings(apiGatewayID)
	if err != nil {
		return err
	}
	_, err = c.APIGatewayV2().DeleteApi(&apigatewayv2.DeleteApiInput{
		ApiId: aws.String(apiGatewayID),
	})
	if err != nil {
		return errors.Wrap(err, "failed to delete api gateway "+apiGatewayID)
	}
	return nil
}
func (c *Client) DeleteAPIGatewayMappingsForDomainName(apiGatewayID string, domainName string) error {
	var nextToken *string
	for {
		apiMappings, err := c.APIGatewayV2().GetApiMappings(&apigatewayv2.GetApiMappingsInput{
			DomainName: aws.String(domainName),
			NextToken:  nextToken,
		})
		if err != nil {
			return errors.Wrap(err, "failed to get api mappings")
		}
		for _, apiMapping := range apiMappings.Items {
			if *apiMapping.ApiId != apiGatewayID {
				continue
			}
			_, err := c.APIGatewayV2().DeleteApiMapping(&apigatewayv2.DeleteApiMappingInput{
				DomainName:   aws.String(domainName),
				ApiMappingId: apiMapping.ApiMappingId,
			})
			if err != nil {
				return errors.Wrap(err, fmt.Sprintf("failed to delete api mapping %s in domain %s", *apiMapping.ApiMappingId, domainName))
			}
		}
		nextToken = apiMappings.NextToken
		if nextToken == nil {
			break
		}
	}
	return nil
}
func (c *Client) DeleteAPIGatewayMappings(apiGatewayID string) error {
	var nextToken *string
	for {
		domainNames, err := c.APIGatewayV2().GetDomainNames(&apigatewayv2.GetDomainNamesInput{
			NextToken: nextToken,
		})
		if err != nil {
			return errors.Wrap(err, "failed to get domain names")
		}
		for _, domainName := range domainNames.Items {
			err := c.DeleteAPIGatewayMappingsForDomainName(apiGatewayID, *domainName.DomainName)
			if err != nil {
				return err
			}
		}
		nextToken = domainNames.NextToken
		if nextToken == nil {
			break
		}
	}
	return nil
}
func (c *Client) GetVPCLinkIntegration(apiGatewayID string, vpcLinkID string) (*apigatewayv2.Integration, error) {
	var nextToken *string
	for {
		integrations, err := c.APIGatewayV2().GetIntegrations(&apigatewayv2.GetIntegrationsInput{
			ApiId:     &apiGatewayID,
			NextToken: nextToken,
		})
		if err != nil {
			return nil, errors.Wrap(err, "failed to get api gateway integrations for api gateway "+apiGatewayID)
		}
		for _, integration := range integrations.Items {
			if *integration.ConnectionId == vpcLinkID {
				return integration, nil
			}
		}
		nextToken = integrations.NextToken
		if nextToken == nil {
			break
		}
	}
	return nil, nil
}
func (c *Client) GetRouteIntegrationID(apiGatewayID string, endpoint string) (string, error) {
	route, err := c.GetRoute(apiGatewayID, endpoint)
	if err != nil {
		return "", err
	}
	if route == nil {
		return "", nil
	}
	return ExtractRouteIntegrationID(route), nil
}
func ExtractRouteIntegrationID(route *apigatewayv2.Route) string {
	if route == nil || route.Target == nil {
		return ""
	}
	integrationID := strings.TrimPrefix(*route.Target, "integrations/")
	return integrationID
}