Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find origin by domain name and path #6880

Merged
merged 3 commits into from Oct 28, 2019
Merged

Conversation

DanConway
Copy link

What did you implement

Use both the domain name and the origin path to determine if two origins are equal

Closes #6864

How can we verify it

Unit test has been added.

The following serverless.yaml should create two origins, previously only one was created

service:
  name: cloudfront-test

provider:
  name: aws
  runtime: nodejs10.x

functions:
  first:
    handler: first.handler
    events:
      - cloudFront:
          eventType: viewer-request
          origin: s3://bucketname.s3.amazonaws.com/files
  second:
    handler: second.handler
    events:
      - cloudFront:
          eventType: viewer-request
          pathPattern: /second
          origin: s3://bucketname.s3.amazonaws.com/files

Todos

  • Write and run all tests
  • Enable "Allow edits from maintainers" for this PR
  • Update the messages below

Is this ready for review?: YES
Is it a breaking change?: NO

Copy link
Contributor

@pmuens pmuens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this @DanConway 👍

I just tested the fix with the following serverless.yml and only one origin entry is created. Am I missing something?

service: test-${self:custom.idx}

provider:
  name: aws
  runtime: nodejs10.x
  versionFunctions: false
  region: us-east-1
  stage: dev

custom:
  idx: 0

functions:
  hello:
    handler: functions/handler.handler
    events:
      - cloudFront:
          eventType: viewer-response
          origin: https://serverless.com/framework/docs
  world:
    handler: functions/handler.handler
    events:
      - cloudFront:
          eventType: viewer-response
          pathPattern: /second
          origin: https://serverless.com/framework/docs

Do you know if this is a breaking change when dealing with existing deployments?

Also /ccing @laardee here who implemented Lambda@Edge...

@DanConway
Copy link
Author

DanConway commented Oct 27, 2019

Hi @pmuens,

In that example should only create one origin as the domain and path are the same. Where there is currently an issue is if you are seeing up Cloudfront to target the root of two separate websites/buckets or a folder with the same name in two separate sites/buckets.

Previously it only matched on origin path so, for example, if you tried to use https://hello.com and https://world.com as the origins (or https://hello.com/admin and https://world.com/admin it would previously only create the first but should now create both.

I don't believe it would be a breaking change as previously it wouldn't create an origin you needed.

Copy link
Contributor

@pmuens pmuens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for getting back @DanConway 👍

That makes sense. I just tested it again today with the serverless.yml at the bottom. Everything worked as expected! Thanks for fixing this LGTM :shipit:

service: test-${self:custom.idx}

provider:
  name: aws
  runtime: nodejs10.x
  versionFunctions: false

custom:
  idx: 0

functions:
  hello:
    handler: functions/handler.handler
    events:
      - cloudFront:
          eventType: viewer-response
          origin: https://serverless.com/framework/docs
  world:
    handler: functions/handler.handler
    events:
      - cloudFront:
          eventType: viewer-response
          pathPattern: /second
          origin: https://serverless.org/framework/docs

@pmuens pmuens merged commit f783888 into serverless:master Oct 28, 2019
@pmuens pmuens added this to the 1.56.0 milestone Oct 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cloudFront events using originPath to distinguish origins
2 participants