2

I want to have multiple (based on stage param) AWS cloudfront distribution. So if --stage dev passed it would deploy a different CloudFront dist than --stage qa. Each stage should update/create a distribution based on the stage params.

Is it possible to achieve with serverless.yml?

I have found the following plugin serverless-api-cloudfront , not sure it will create additional distribution if domain name is changed, and not sure it is possible to add origins with this plugin.

Thanks

1 Answer 1

2

Is it possible to achieve with serverless.yml?

Yes. Yes it's possible and it's already built in. Your config will be simpler if you use the plugin serverless-api-cloudfront (rather than declaring a AWS::CloudFront::Distribution resource yourself). You will get one distribution-per-stage, without having to jump through any hoops.

** EDIT

Expanding on my original post: It does seem that the serverless-api-cloudfront plugin's README is lacking in usage examples (at the time of this writing). I do suggest that anyone reading this post should go to the plugin's github and help the author by PR'ing a better README.

Here's a link to a blog article I found that shows an example of how to write up a AWS::CloudFront::Distribution directly in your serverless.yml. It's only 1 resource, so you may not even want to depend on a plugin anyway. https://medium.com/yld-blog/caching-in-with-cloudfront-using-serverless-5a174651ab14

Sign up to request clarification or add additional context in comments.

3 Comments

thanks! but how can I add origins and behaviours to this distribution? not much documentation there?
@AlexPortnoy updated my original answer, but TL;DR go to this link for inspiration on configuring a AWS::CloudFront::Distribution directly in your serverless.yml without any plugins. medium.com/yld-blog/…
I also noticed that the plugin does create an api-gateway with the distribution. That I do not need / want. But the blog is great!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.