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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/plugins/aws/package/compile/events/cloudFront/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@ class AwsCompileCloudFrontEvents {

let origin = createOrigin(functionName, event.cloudFront.origin, this.provider.naming);

const existingOrigin = _.find(origins, o => o.OriginPath === origin.OriginPath);
const existingOrigin = _.find(
origins,
o => o.DomainName === origin.DomainName && o.OriginPath === origin.OriginPath
);

if (!existingOrigin) {
origins.push(origin);
Expand Down
64 changes: 64 additions & 0 deletions lib/plugins/aws/package/compile/events/cloudFront/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,5 +410,69 @@ describe('AwsCompileCloudFrontEvents', () => {
S3OriginConfig: {},
});
});

it('should create different origins for different domains with the same path', () => {
awsCompileCloudFrontEvents.serverless.service.functions = {
first: {
name: 'first',
events: [
{
cloudFront: {
eventType: 'viewer-request',
origin: 's3://bucketname.s3.amazonaws.com/files',
},
},
],
},
second: {
name: 'second',
events: [
{
cloudFront: {
eventType: 'viewer-request',
origin: 's3://anotherbucket.s3.amazonaws.com/files',
},
},
],
},
};

awsCompileCloudFrontEvents.serverless.service.provider.compiledCloudFormationTemplate.Resources = {
FirstLambdaFunction: {
Type: 'AWS::Lambda::Function',
Properties: {
FunctionName: 'first',
},
},
SecondLambdaFunction: {
Type: 'AWS::Lambda::Function',
Properties: {
FunctionName: 'second',
},
},
};

awsCompileCloudFrontEvents.compileCloudFrontEvents();

expect(
awsCompileCloudFrontEvents.serverless.service.provider.compiledCloudFormationTemplate
.Resources.CloudFrontDistribution.Properties.DistributionConfig.Origins[0]
).to.eql({
Id: 'First/files',
DomainName: 'bucketname.s3.amazonaws.com',
OriginPath: '/files',
S3OriginConfig: {},
});

expect(
awsCompileCloudFrontEvents.serverless.service.provider.compiledCloudFormationTemplate
.Resources.CloudFrontDistribution.Properties.DistributionConfig.Origins[1]
).to.eql({
Id: 'Second/files',
DomainName: 'anotherbucket.s3.amazonaws.com',
OriginPath: '/files',
S3OriginConfig: {},
});
});
});
});