serverless-components / aws-cloudfront

Deploy an AWS CloudFront distribution for the provided origins using Serverless Components
https://serverless.com
Apache License 2.0
27 stars 12 forks source link

Add cache behavior support #1

Closed danielcondemarin closed 5 years ago

danielcondemarin commented 5 years ago

Adds support for setting origin cache behaviors.

For example:

# serverless.yml
distribution:
  component: '@serverless/aws-cloudfront'
  inputs:
    origins:
      - 
        url: https://my-assets.com
        pathPatterns:
          /static/images: # route any /static/images requests to https://my-assets.com
            ttl: 10

Or you could mix simple string origins with complex ones:

# serverless.yml

distribution:
  component: '@serverless/aws-cloudfront'
  inputs:
    origins:
      - http://mybucket.s3.amazonaws.com # default cache behavior uses this origin
      - 
        url: https://my-assets.com
        pathPatterns:
          /static/images: # route any /static/images requests to https://my-assets.com
            ttl: 10

A few notes:

Also, I’m using jest snapshots to test whats being passed to createDistribution and updateDistribution. This was the best way I found to make sure I don’t break existing behavior, without having to add a ton of tests considering the amount of fields cloudfront needs passing in the api.