Skip to content

Commit 6ba193a

Browse files
Merge branch 'master' into serve-private-S3-content-through-cloudfront
2 parents 1890284 + 4c7b4c1 commit 6ba193a

File tree

9 files changed

+410
-155
lines changed

9 files changed

+410
-155
lines changed

README.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ distribution:
5454
- https://my-bucket.s3.amazonaws.com
5555
```
5656
57-
#### Complex origin objects
58-
59-
You can extend your origins configuration by declaring them as objects. For example, to add cache behaviors:
57+
#### Custom cache behavior
6058
6159
```yml
6260
# serverless.yml
@@ -71,6 +69,23 @@ distribution:
7169
ttl: 10
7270
```
7371
72+
#### Lambda@Edge
73+
74+
```yml
75+
# serverless.yml
76+
77+
distribution:
78+
component: '@serverless/aws-cloudfront'
79+
inputs:
80+
origins:
81+
- url: https://sampleorigin.com
82+
pathPatterns:
83+
/sample/path:
84+
ttl: 10
85+
lambda@edge:
86+
viewer-request: arn:aws:lambda:us-east-1:123:function:myFunc:version # lambda ARN including version
87+
```
88+
7489
### 4. Deploy
7590
7691
```console
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Input origin as a custom url creates distribution with lambda associations for each event type 1`] = `
4+
Object {
5+
"DistributionConfig": Object {
6+
"Aliases": Object {
7+
"Items": Array [],
8+
"Quantity": 0,
9+
},
10+
"CacheBehaviors": Object {
11+
"Items": Array [
12+
Object {
13+
"AllowedMethods": Object {
14+
"CachedMethods": Object {
15+
"Items": Array [
16+
"GET",
17+
"HEAD",
18+
],
19+
"Quantity": 2,
20+
},
21+
"Items": Array [
22+
"GET",
23+
"HEAD",
24+
],
25+
"Quantity": 2,
26+
},
27+
"Compress": true,
28+
"DefaultTTL": 10,
29+
"FieldLevelEncryptionId": "",
30+
"ForwardedValues": Object {
31+
"Cookies": Object {
32+
"Forward": "all",
33+
},
34+
"Headers": Object {
35+
"Items": Array [],
36+
"Quantity": 0,
37+
},
38+
"QueryString": true,
39+
"QueryStringCacheKeys": Object {
40+
"Items": Array [],
41+
"Quantity": 0,
42+
},
43+
},
44+
"LambdaFunctionAssociations": Object {
45+
"Items": Array [
46+
Object {
47+
"EventType": "viewer-request",
48+
"IncludeBody": true,
49+
"LambdaFunctionARN": "arn:aws:lambda:us-east-1:123:function:viewerRequestFunction",
50+
},
51+
Object {
52+
"EventType": "origin-request",
53+
"IncludeBody": true,
54+
"LambdaFunctionARN": "arn:aws:lambda:us-east-1:123:function:originRequestFunction",
55+
},
56+
Object {
57+
"EventType": "origin-response",
58+
"IncludeBody": true,
59+
"LambdaFunctionARN": "arn:aws:lambda:us-east-1:123:function:originResponseFunction",
60+
},
61+
Object {
62+
"EventType": "viewer-response",
63+
"IncludeBody": true,
64+
"LambdaFunctionARN": "arn:aws:lambda:us-east-1:123:function:viewerResponseFunction",
65+
},
66+
],
67+
"Quantity": 4,
68+
},
69+
"MaxTTL": 10,
70+
"MinTTL": 10,
71+
"PathPattern": "/some/path",
72+
"SmoothStreaming": false,
73+
"TargetOriginId": "exampleorigin.com",
74+
"TrustedSigners": Object {
75+
"Enabled": false,
76+
"Quantity": 0,
77+
},
78+
"ViewerProtocolPolicy": "https-only",
79+
},
80+
],
81+
"Quantity": 1,
82+
},
83+
"CallerReference": "1566599541192",
84+
"Comment": "",
85+
"DefaultCacheBehavior": Object {
86+
"AllowedMethods": Object {
87+
"CachedMethods": Object {
88+
"Items": Array [
89+
"HEAD",
90+
"GET",
91+
],
92+
"Quantity": 2,
93+
},
94+
"Items": Array [
95+
"HEAD",
96+
"GET",
97+
],
98+
"Quantity": 2,
99+
},
100+
"Compress": false,
101+
"DefaultTTL": 86400,
102+
"FieldLevelEncryptionId": "",
103+
"ForwardedValues": Object {
104+
"Cookies": Object {
105+
"Forward": "none",
106+
},
107+
"Headers": Object {
108+
"Items": Array [],
109+
"Quantity": 0,
110+
},
111+
"QueryString": false,
112+
"QueryStringCacheKeys": Object {
113+
"Items": Array [],
114+
"Quantity": 0,
115+
},
116+
},
117+
"LambdaFunctionAssociations": Object {
118+
"Items": Array [],
119+
"Quantity": 0,
120+
},
121+
"MaxTTL": 31536000,
122+
"MinTTL": 0,
123+
"SmoothStreaming": false,
124+
"TargetOriginId": "exampleorigin.com",
125+
"TrustedSigners": Object {
126+
"Enabled": false,
127+
"Items": Array [],
128+
"Quantity": 0,
129+
},
130+
"ViewerProtocolPolicy": "redirect-to-https",
131+
},
132+
"Enabled": true,
133+
"HttpVersion": "http2",
134+
"Origins": Object {
135+
"Items": Array [
136+
Object {
137+
"CustomHeaders": Object {
138+
"Items": Array [],
139+
"Quantity": 0,
140+
},
141+
"CustomOriginConfig": Object {
142+
"HTTPPort": 80,
143+
"HTTPSPort": 443,
144+
"OriginKeepaliveTimeout": 5,
145+
"OriginProtocolPolicy": "https-only",
146+
"OriginReadTimeout": 30,
147+
"OriginSslProtocols": Object {
148+
"Items": Array [
149+
"TLSv1.2",
150+
],
151+
"Quantity": 1,
152+
},
153+
},
154+
"DomainName": "exampleorigin.com",
155+
"Id": "exampleorigin.com",
156+
"OriginPath": "",
157+
},
158+
],
159+
"Quantity": 1,
160+
},
161+
"PriceClass": "PriceClass_All",
162+
},
163+
}
164+
`;
Lines changed: 41 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { createComponent } = require('../test-utils')
1+
const { createComponent, assertHasOrigin } = require('../test-utils')
22

33
const {
44
mockCreateDistribution,
@@ -26,36 +26,26 @@ describe('Input origin as a custom url', () => {
2626
origins: ['https://mycustomorigin.com']
2727
})
2828

29-
expect(mockCreateDistribution).toBeCalledWith(
30-
expect.objectContaining({
31-
DistributionConfig: expect.objectContaining({
32-
Origins: expect.objectContaining({
33-
Items: [
34-
{
35-
Id: 'mycustomorigin.com',
36-
DomainName: 'mycustomorigin.com',
37-
CustomOriginConfig: {
38-
HTTPPort: 80,
39-
HTTPSPort: 443,
40-
OriginProtocolPolicy: 'https-only',
41-
OriginSslProtocols: {
42-
Quantity: 1,
43-
Items: ['TLSv1.2']
44-
},
45-
OriginReadTimeout: 30,
46-
OriginKeepaliveTimeout: 5
47-
},
48-
CustomHeaders: {
49-
Quantity: 0,
50-
Items: []
51-
},
52-
OriginPath: ''
53-
}
54-
]
55-
})
56-
})
57-
})
58-
)
29+
assertHasOrigin(mockCreateDistribution, {
30+
Id: 'mycustomorigin.com',
31+
DomainName: 'mycustomorigin.com',
32+
CustomOriginConfig: {
33+
HTTPPort: 80,
34+
HTTPSPort: 443,
35+
OriginProtocolPolicy: 'https-only',
36+
OriginSslProtocols: {
37+
Quantity: 1,
38+
Items: ['TLSv1.2']
39+
},
40+
OriginReadTimeout: 30,
41+
OriginKeepaliveTimeout: 5
42+
},
43+
CustomHeaders: {
44+
Quantity: 0,
45+
Items: []
46+
},
47+
OriginPath: ''
48+
})
5949
expect(mockCreateDistribution.mock.calls[0][0]).toMatchSnapshot()
6050
})
6151

@@ -82,37 +72,26 @@ describe('Input origin as a custom url', () => {
8272
origins: ['https://mycustomoriginupdated.com']
8373
})
8474

85-
expect(mockUpdateDistribution).toBeCalledWith(
86-
expect.objectContaining({
87-
DistributionConfig: expect.objectContaining({
88-
Origins: expect.objectContaining({
89-
Items: [
90-
{
91-
Id: 'mycustomoriginupdated.com',
92-
DomainName: 'mycustomoriginupdated.com',
93-
CustomOriginConfig: {
94-
HTTPPort: 80,
95-
HTTPSPort: 443,
96-
OriginProtocolPolicy: 'https-only',
97-
OriginSslProtocols: {
98-
Quantity: 1,
99-
Items: ['TLSv1.2']
100-
},
101-
OriginReadTimeout: 30,
102-
OriginKeepaliveTimeout: 5
103-
},
104-
CustomHeaders: {
105-
Quantity: 0,
106-
Items: []
107-
},
108-
OriginPath: ''
109-
}
110-
]
111-
})
112-
})
113-
})
114-
)
115-
75+
assertHasOrigin(mockUpdateDistribution, {
76+
Id: 'mycustomoriginupdated.com',
77+
DomainName: 'mycustomoriginupdated.com',
78+
CustomOriginConfig: {
79+
HTTPPort: 80,
80+
HTTPSPort: 443,
81+
OriginProtocolPolicy: 'https-only',
82+
OriginSslProtocols: {
83+
Quantity: 1,
84+
Items: ['TLSv1.2']
85+
},
86+
OriginReadTimeout: 30,
87+
OriginKeepaliveTimeout: 5
88+
},
89+
CustomHeaders: {
90+
Quantity: 0,
91+
Items: []
92+
},
93+
OriginPath: ''
94+
})
11695
expect(mockUpdateDistribution.mock.calls[0][0]).toMatchSnapshot()
11796
})
11897
})

0 commit comments

Comments
 (0)