Droplr / serverless-api-cloudfront

Serverless Plugin - CloudFront distribution in front of your API Gateway

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

distribution per stage

hmoffatt opened this issue · comments

Is it possible to set up a different cloudfront distribution depending on which stage is being deployed? And/or make deployment conditional on which stage?

I would like to have a different one for development and production, or possibly not bother with one for development at all.

Hi, distribution "per-stage" is a default behaviour of that plugin. However serverless is not using API Gateways staging model, it instead just creates separate API GWs:

Sorry to come back to this so late, I am only just going back to my project now.

I understand how the serverless staging is using the API gateway, that's fine. But if I am using serverless-api-cloudfront I need to be able to specify a custom domain for each stage, else they will all try to claim the same domain name, won't they? I don't see anything in the code or the example config that deals with this.

Per-stage certificate and other settings may also be needed.

I figured out that this can be done with magic in the main config. Maybe this could be added to the instructions.

custom:
  apiCloudFront-dev:
    domain: xyz.com
    certificate: arn:aws:acm:us-east-1:...

  apiCloudFront-prod:
    domain: abc.com
    certificate: arn:aws:acm:us-east-1:...

  apiCloudFront: ${self:custom.apiCloudFront-${self:provider.stage}}