serverless icon indicating copy to clipboard operation
serverless copied to clipboard

Stages Create new API Gateway Endpoint, Instead of new API Gateway Stages

Open j0rd opened this issue 10 years ago • 10 comments

I've made a Shopify Shipping Cost Calculator using serverless v0.5.

I had a single codebase and would create a new stage per store integration (I maintain around 5 stores).

In the past, each stage would use the same API Gateway endpoint URL, and each stage would have a URL prefix.

I've noticed in moving to v1.0 that each stage now receives it's own API Gateway URL endpoint + 1 single stage

Previously, I received 1 API Gateway URL endpoint + multiple stages.

Is this expected behaviour, or something that's been overlooked or perhaps coded wrong.

I would assume 1 API Gateway URL endpoint + multiple stages is more correct.

Please excuse me if I've used the wrong terminology, as I'm new so all this AWS speak.

j0rd avatar Sep 08 '16 11:09 j0rd

yup this problem is very annoying, IMHO It should be in top priorities... it also causes problem with custom domain mapping like I reported here

I think AWS did not design APIG to be used like this ?

ghost avatar Sep 08 '16 14:09 ghost

I reported this already: https://github.com/serverless/serverless/issues/1907 and it was closed because were ticket already created, ticket was solved (https://github.com/serverless/serverless/pull/1834) and merged in rc but I think the idea was missed in the middle, maybe I am confused on it, can someone tell me if I am thinking wrong regarding this? thank =)

rogemita avatar Sep 08 '16 19:09 rogemita

there is two needs I think:

a) one API containing a merge of all services routes (I think it is the way AWS intented the use of APIs with custom domains and would allow versioned urls like custom-domain/v1/service ) This may be only achieved by #2074 maybe idk ?

b) one API per service (but will only somewhat play well with custom domains if #1738 is fixed. And one would need to manually map each custom domain base path to service and it would not allow custom-domain/v1/service urls but only v1.custom-domain.com/service url which is quite :| )

considering how AWS built custom domain API mapping, a) seems better solution imho

ghost avatar Sep 09 '16 04:09 ghost

Agree with this, option a) would be best, hope this is addressed soon :)

kurtmaile avatar Sep 09 '16 08:09 kurtmaile

I run into this problem also. I agree the option a) would be the best :)

yuhwan avatar Sep 13 '16 16:09 yuhwan

I would assume that you could implement this yourself by having a resource defined at the bottom that overrides the endpoint that the service will be deployed to. That should get you to the point you are looking for quite quickly and easily. I believe the resource you need to overwrite is ApiGatewayRestApi http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html.

andymac4182 avatar Sep 13 '16 21:09 andymac4182

@andymac4182 as each service has his own stack, it means the resource could overwrite any APIG in any stack?

ghost avatar Sep 14 '16 03:09 ghost

Unfortunately supporting stages as they're implemented by API GW would break the separation between environments (e.g. development vs production) that is often required in the real world - most companies don't want their production applications installed in the same account as their development applications as it makes restricting access to production (i.e. who can edit/delete production) much harder than it needs to be.

Given API GW is the only AWS service (that I can think of) that has the idea of stages, I don't think it's beneficial to tie Serverless to it too tightly. Given you would have to change the URL paths anyway, is it really such a big deal to change the domain name?

rowanu avatar Sep 14 '16 03:09 rowanu

I feel similarly to @rowanu. This past week I converted our production SLS app from 0.5.x to 1.0.0-rc1. At first I was a little disappointed in the change to the APIGW. But as I've thought about it more, I'm happy to see it as it's working now. Like @rowanu mentions, we have separate accounts for dev and PRD. So our developers all have a stage that's their username in the dev account. Then our QA, PRD, Staging, etc builds are in the production account.

The separation by the 1.0 way of doing things is nice because sometimes something happens and your CDN stack gets stuck, or you have some odd change or problem. If each of the stages is a totally separate API then I have no problem just nuking the whole stack and not worrying about adverse affects to the PRD endpoints. The separation of concerns is nice, and also as @rowanu mentions, APIGW is basically the only product that supports integration between your stages/environments, so you'll be forced into having that separation everywhere else - so might as well be consistent with the API.

As far as sharing a custom domain for different stages - I think in general stages are used for environments (dev, QA, PRD), so you don't really want a shared domain (in most cases you don't want dev that open). For @j0rd's usecase of different stores on a single domain, I would suggest front-ending APIGW with some other edge that just does proxying - that could be a CloudFront domain or an external vendor. That gives you a lot better flexibility for A/B testing, changing out implementations, etc also.

jthomerson avatar Sep 14 '16 12:09 jthomerson

Closing this issue as there is no way around it at the moment with Cloudformation deployment. In the future we're going to work on allowing you to build a service that deploys API Gateway and then references other functions.

flomotlik avatar Nov 05 '16 14:11 flomotlik