@friggframework/devtools 2.0.0--canary.743.d13a976.0 → 2.0.0--canary.745.0209482d.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/frigg-cli/README.md +41 -1
- package/frigg-cli/generate-command/__tests__/generate-command.test.js +36 -0
- package/frigg-cli/generate-command/index.js +3 -1
- package/frigg-cli/generate-command/terraform-generator.js +48 -0
- package/frigg-cli/generate-iam-command.js +1 -0
- package/frigg-cli/index.js +8 -0
- package/frigg-cli/templates/backend/README.md +3 -2
- package/frigg-cli/tls-check-command/__tests__/check-post-quantum-tls.test.js +396 -0
- package/frigg-cli/tls-check-command/__tests__/tls-check-command.test.js +182 -0
- package/frigg-cli/tls-check-command/check-post-quantum-tls.js +194 -0
- package/frigg-cli/tls-check-command/index.js +136 -0
- package/frigg-cli/validate-command/__tests__/validate-app-definition.test.js +69 -0
- package/frigg-cli/validate-command/checks/config.js +59 -0
- package/infrastructure/app-definition-schema-contract.test.js +10 -0
- package/infrastructure/domains/edge/cloudfront-builder.js +237 -0
- package/infrastructure/domains/edge/cloudfront-builder.test.js +273 -0
- package/infrastructure/domains/integration/integration-builder.js +1 -34
- package/infrastructure/domains/integration/integration-builder.test.js +0 -86
- package/infrastructure/domains/security/iam-generator.js +45 -2
- package/infrastructure/domains/security/iam-generator.test.js +23 -0
- package/infrastructure/domains/security/templates/iam-policy-full.json +30 -1
- package/infrastructure/domains/shared/builder-orchestrator.js +6 -0
- package/infrastructure/domains/shared/builder-orchestrator.test.js +30 -0
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +9 -2
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +11 -0
- package/infrastructure/infrastructure-composer.js +8 -0
- package/infrastructure/infrastructure-composer.test.js +35 -0
- package/package.json +7 -7
- package/infrastructure/domains/integration/queue-worker-concurrency.js +0 -85
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CloudFront Builder
|
|
3
|
+
*
|
|
4
|
+
* Domain Layer - Hexagonal Architecture
|
|
5
|
+
*
|
|
6
|
+
* Opt-in CloudFront distribution in front of the app's HTTP API.
|
|
7
|
+
*
|
|
8
|
+
* Why: API Gateway HTTP APIs support only the TLS_1_2 security policy, which
|
|
9
|
+
* has no post-quantum key exchange. CloudFront prefers hybrid post-quantum key
|
|
10
|
+
* exchange (X25519MLKEM768) on every TLS security policy for client-to-edge
|
|
11
|
+
* connections. With this builder, clients that use the CloudFront URL get
|
|
12
|
+
* post-quantum protection against "harvest now, decrypt later".
|
|
13
|
+
*
|
|
14
|
+
* Limits (documented in docs/reference/post-quantum-readiness.md):
|
|
15
|
+
* - The CloudFront-to-API Gateway connection is classical TLS (AWS: origin
|
|
16
|
+
* support is "coming soon").
|
|
17
|
+
* - The execute-api URL stays reachable with classical TLS.
|
|
18
|
+
* - The WebSocket API is not covered.
|
|
19
|
+
*
|
|
20
|
+
* Configuration (app definition):
|
|
21
|
+
* cloudFront: {
|
|
22
|
+
* enable: true,
|
|
23
|
+
* priceClass: 'PriceClass_100', // optional
|
|
24
|
+
* domainNames: ['api.example.com'], // optional, with certificateArn
|
|
25
|
+
* certificateArn: 'arn:aws:acm:us-east-1:...', // ACM, us-east-1 only
|
|
26
|
+
* }
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
const {
|
|
30
|
+
InfrastructureBuilder,
|
|
31
|
+
ValidationResult,
|
|
32
|
+
} = require('../shared/base-builder');
|
|
33
|
+
|
|
34
|
+
/** AWS managed cache policy "Managed-CachingDisabled". */
|
|
35
|
+
const CACHING_DISABLED_POLICY_ID = '4135ea2d-6df8-44a3-9df3-4b5a84be39ad';
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* AWS managed origin request policy "Managed-AllViewerExceptHostHeader":
|
|
39
|
+
* forwards all viewer headers (Authorization included), cookies and query
|
|
40
|
+
* strings, but not Host, which API Gateway needs to be its own host name.
|
|
41
|
+
*/
|
|
42
|
+
const ALL_VIEWER_EXCEPT_HOST_HEADER_POLICY_ID =
|
|
43
|
+
'b689b0a8-53d0-40ab-baf2-68738e2966ac';
|
|
44
|
+
|
|
45
|
+
const PRICE_CLASSES = ['PriceClass_100', 'PriceClass_200', 'PriceClass_All'];
|
|
46
|
+
const DEFAULT_PRICE_CLASS = 'PriceClass_100';
|
|
47
|
+
const ORIGIN_ID = 'FriggHttpApi';
|
|
48
|
+
const DISTRIBUTION_LOGICAL_ID = 'FriggCloudFrontDistribution';
|
|
49
|
+
const ACM_US_EAST_1_ARN =
|
|
50
|
+
/^arn:aws[a-z-]*:acm:us-east-1:\d{12}:certificate\/[A-Za-z0-9-]+$/;
|
|
51
|
+
|
|
52
|
+
class CloudFrontBuilder extends InfrastructureBuilder {
|
|
53
|
+
constructor() {
|
|
54
|
+
super();
|
|
55
|
+
this.name = 'CloudFrontBuilder';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
shouldExecute(appDefinition) {
|
|
59
|
+
// Local builds (frigg start) deploy nothing to AWS.
|
|
60
|
+
if (process.env.FRIGG_SKIP_AWS_DISCOVERY === 'true') {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
return appDefinition.cloudFront?.enable === true;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
getDependencies() {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
validate(appDefinition) {
|
|
71
|
+
const result = new ValidationResult();
|
|
72
|
+
const config = appDefinition.cloudFront || {};
|
|
73
|
+
|
|
74
|
+
if (
|
|
75
|
+
config.priceClass !== undefined &&
|
|
76
|
+
!PRICE_CLASSES.includes(config.priceClass)
|
|
77
|
+
) {
|
|
78
|
+
result.addError(
|
|
79
|
+
`cloudFront.priceClass must be one of ${PRICE_CLASSES.join(
|
|
80
|
+
', '
|
|
81
|
+
)}.`
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const hasDomainNames = config.domainNames !== undefined;
|
|
86
|
+
const hasCertificate = config.certificateArn !== undefined;
|
|
87
|
+
|
|
88
|
+
if (
|
|
89
|
+
hasDomainNames &&
|
|
90
|
+
(!Array.isArray(config.domainNames) ||
|
|
91
|
+
config.domainNames.length === 0 ||
|
|
92
|
+
!config.domainNames.every(
|
|
93
|
+
(name) => typeof name === 'string' && name.length > 0
|
|
94
|
+
))
|
|
95
|
+
) {
|
|
96
|
+
result.addError(
|
|
97
|
+
'cloudFront.domainNames must be a non-empty list of host names.'
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
if (hasDomainNames && !hasCertificate) {
|
|
101
|
+
result.addError(
|
|
102
|
+
'cloudFront.domainNames needs cloudFront.certificateArn (an ACM certificate in us-east-1).'
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
if (hasCertificate && !hasDomainNames) {
|
|
106
|
+
result.addError(
|
|
107
|
+
'cloudFront.certificateArn needs cloudFront.domainNames.'
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
if (
|
|
111
|
+
hasCertificate &&
|
|
112
|
+
!ACM_US_EAST_1_ARN.test(String(config.certificateArn))
|
|
113
|
+
) {
|
|
114
|
+
result.addError(
|
|
115
|
+
'cloudFront.certificateArn must be an ACM certificate ARN in us-east-1. CloudFront reads certificates only from us-east-1.'
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async build(appDefinition) {
|
|
123
|
+
console.log(
|
|
124
|
+
`\n[${this.name}] Configuring CloudFront in front of the HTTP API...`
|
|
125
|
+
);
|
|
126
|
+
const config = appDefinition.cloudFront || {};
|
|
127
|
+
const hasCustomDomain =
|
|
128
|
+
Array.isArray(config.domainNames) && config.domainNames.length > 0;
|
|
129
|
+
|
|
130
|
+
const distributionConfig = {
|
|
131
|
+
Enabled: true,
|
|
132
|
+
// CloudFront allows 128 characters; a stack name is at most 128.
|
|
133
|
+
Comment: '${self:service}-${self:provider.stage}',
|
|
134
|
+
HttpVersion: 'http2and3',
|
|
135
|
+
IPV6Enabled: true,
|
|
136
|
+
PriceClass: config.priceClass || DEFAULT_PRICE_CLASS,
|
|
137
|
+
Origins: [
|
|
138
|
+
{
|
|
139
|
+
Id: ORIGIN_ID,
|
|
140
|
+
DomainName: {
|
|
141
|
+
'Fn::Join': [
|
|
142
|
+
'',
|
|
143
|
+
[
|
|
144
|
+
{ Ref: 'HttpApi' },
|
|
145
|
+
'.execute-api.',
|
|
146
|
+
{ Ref: 'AWS::Region' },
|
|
147
|
+
'.amazonaws.com',
|
|
148
|
+
],
|
|
149
|
+
],
|
|
150
|
+
},
|
|
151
|
+
CustomOriginConfig: {
|
|
152
|
+
OriginProtocolPolicy: 'https-only',
|
|
153
|
+
OriginSSLProtocols: ['TLSv1.2'],
|
|
154
|
+
// API Gateway ends HTTP API requests after 30 s.
|
|
155
|
+
OriginReadTimeout: 30,
|
|
156
|
+
OriginKeepaliveTimeout: 5,
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
DefaultCacheBehavior: {
|
|
161
|
+
TargetOriginId: ORIGIN_ID,
|
|
162
|
+
ViewerProtocolPolicy: 'https-only',
|
|
163
|
+
AllowedMethods: [
|
|
164
|
+
'GET',
|
|
165
|
+
'HEAD',
|
|
166
|
+
'OPTIONS',
|
|
167
|
+
'PUT',
|
|
168
|
+
'PATCH',
|
|
169
|
+
'POST',
|
|
170
|
+
'DELETE',
|
|
171
|
+
],
|
|
172
|
+
CachedMethods: ['GET', 'HEAD'],
|
|
173
|
+
CachePolicyId: CACHING_DISABLED_POLICY_ID,
|
|
174
|
+
OriginRequestPolicyId: ALL_VIEWER_EXCEPT_HOST_HEADER_POLICY_ID,
|
|
175
|
+
},
|
|
176
|
+
ViewerCertificate: hasCustomDomain
|
|
177
|
+
? {
|
|
178
|
+
AcmCertificateArn: config.certificateArn,
|
|
179
|
+
SslSupportMethod: 'sni-only',
|
|
180
|
+
MinimumProtocolVersion: 'TLSv1.2_2021',
|
|
181
|
+
}
|
|
182
|
+
: { CloudFrontDefaultCertificate: true },
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
if (hasCustomDomain) {
|
|
186
|
+
distributionConfig.Aliases = [...config.domainNames];
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
console.log(
|
|
190
|
+
` ✓ CloudFront distribution (${distributionConfig.PriceClass}${
|
|
191
|
+
hasCustomDomain ? `, ${config.domainNames.join(', ')}` : ''
|
|
192
|
+
})`
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
return {
|
|
196
|
+
resources: {
|
|
197
|
+
[DISTRIBUTION_LOGICAL_ID]: {
|
|
198
|
+
Type: 'AWS::CloudFront::Distribution',
|
|
199
|
+
Properties: { DistributionConfig: distributionConfig },
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
outputs: {
|
|
203
|
+
FriggCloudFrontUrl: {
|
|
204
|
+
Description:
|
|
205
|
+
'Public URL of the app through CloudFront (hybrid post-quantum TLS for clients)',
|
|
206
|
+
Value: {
|
|
207
|
+
'Fn::Join': [
|
|
208
|
+
'',
|
|
209
|
+
[
|
|
210
|
+
'https://',
|
|
211
|
+
{
|
|
212
|
+
'Fn::GetAtt': [
|
|
213
|
+
DISTRIBUTION_LOGICAL_ID,
|
|
214
|
+
'DomainName',
|
|
215
|
+
],
|
|
216
|
+
},
|
|
217
|
+
],
|
|
218
|
+
],
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
FriggCloudFrontDistributionId: {
|
|
222
|
+
Description: 'CloudFront distribution id',
|
|
223
|
+
Value: { Ref: DISTRIBUTION_LOGICAL_ID },
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
iamStatements: [],
|
|
227
|
+
functions: {},
|
|
228
|
+
environment: {},
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
module.exports = {
|
|
234
|
+
CloudFrontBuilder,
|
|
235
|
+
CACHING_DISABLED_POLICY_ID,
|
|
236
|
+
ALL_VIEWER_EXCEPT_HOST_HEADER_POLICY_ID,
|
|
237
|
+
};
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the CloudFront edge builder: an opt-in CloudFront distribution in
|
|
3
|
+
* front of the HTTP API, so that clients get hybrid post-quantum TLS key
|
|
4
|
+
* exchange (API Gateway HTTP APIs support only the classical TLS_1_2 policy).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const {
|
|
8
|
+
CloudFrontBuilder,
|
|
9
|
+
CACHING_DISABLED_POLICY_ID,
|
|
10
|
+
ALL_VIEWER_EXCEPT_HOST_HEADER_POLICY_ID,
|
|
11
|
+
} = require('./cloudfront-builder');
|
|
12
|
+
|
|
13
|
+
const CERT_ARN =
|
|
14
|
+
'arn:aws:acm:us-east-1:123456789012:certificate/0f1e2d3c-4b5a-6978-8a9b-0c1d2e3f4a5b';
|
|
15
|
+
|
|
16
|
+
describe('CloudFrontBuilder', () => {
|
|
17
|
+
let builder;
|
|
18
|
+
const originalSkipDiscovery = process.env.FRIGG_SKIP_AWS_DISCOVERY;
|
|
19
|
+
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
builder = new CloudFrontBuilder();
|
|
22
|
+
delete process.env.FRIGG_SKIP_AWS_DISCOVERY;
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
afterEach(() => {
|
|
26
|
+
if (originalSkipDiscovery === undefined) {
|
|
27
|
+
delete process.env.FRIGG_SKIP_AWS_DISCOVERY;
|
|
28
|
+
} else {
|
|
29
|
+
process.env.FRIGG_SKIP_AWS_DISCOVERY = originalSkipDiscovery;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe('shouldExecute()', () => {
|
|
34
|
+
it('runs only when cloudFront.enable is true', () => {
|
|
35
|
+
expect(
|
|
36
|
+
builder.shouldExecute({ cloudFront: { enable: true } })
|
|
37
|
+
).toBe(true);
|
|
38
|
+
expect(
|
|
39
|
+
builder.shouldExecute({ cloudFront: { enable: false } })
|
|
40
|
+
).toBe(false);
|
|
41
|
+
expect(builder.shouldExecute({})).toBe(false);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('skips local builds', () => {
|
|
45
|
+
process.env.FRIGG_SKIP_AWS_DISCOVERY = 'true';
|
|
46
|
+
expect(
|
|
47
|
+
builder.shouldExecute({ cloudFront: { enable: true } })
|
|
48
|
+
).toBe(false);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('has no builder dependencies (osls creates the HttpApi)', () => {
|
|
52
|
+
expect(builder.getDependencies()).toEqual([]);
|
|
53
|
+
expect(builder.getName()).toBe('CloudFrontBuilder');
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('validate()', () => {
|
|
58
|
+
it('accepts the minimal configuration', () => {
|
|
59
|
+
const result = builder.validate({ cloudFront: { enable: true } });
|
|
60
|
+
expect(result.errors).toEqual([]);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('accepts a custom domain with a us-east-1 ACM certificate', () => {
|
|
64
|
+
const result = builder.validate({
|
|
65
|
+
cloudFront: {
|
|
66
|
+
enable: true,
|
|
67
|
+
domainNames: ['api.example.com'],
|
|
68
|
+
certificateArn: CERT_ARN,
|
|
69
|
+
priceClass: 'PriceClass_All',
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
expect(result.errors).toEqual([]);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('refuses an unknown price class', () => {
|
|
76
|
+
const result = builder.validate({
|
|
77
|
+
cloudFront: { enable: true, priceClass: 'PriceClass_Cheap' },
|
|
78
|
+
});
|
|
79
|
+
expect(result.errors.join('\n')).toMatch(/priceClass/);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('refuses domainNames without a certificateArn, and the reverse', () => {
|
|
83
|
+
expect(
|
|
84
|
+
builder
|
|
85
|
+
.validate({
|
|
86
|
+
cloudFront: {
|
|
87
|
+
enable: true,
|
|
88
|
+
domainNames: ['api.example.com'],
|
|
89
|
+
},
|
|
90
|
+
})
|
|
91
|
+
.errors.join('\n')
|
|
92
|
+
).toMatch(/certificateArn/);
|
|
93
|
+
expect(
|
|
94
|
+
builder
|
|
95
|
+
.validate({
|
|
96
|
+
cloudFront: { enable: true, certificateArn: CERT_ARN },
|
|
97
|
+
})
|
|
98
|
+
.errors.join('\n')
|
|
99
|
+
).toMatch(/domainNames/);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('refuses a certificate outside us-east-1 (CloudFront reads ACM only there)', () => {
|
|
103
|
+
const result = builder.validate({
|
|
104
|
+
cloudFront: {
|
|
105
|
+
enable: true,
|
|
106
|
+
domainNames: ['api.example.com'],
|
|
107
|
+
certificateArn: CERT_ARN.replace('us-east-1', 'eu-west-1'),
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
expect(result.errors.join('\n')).toMatch(/us-east-1/);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('refuses domainNames that are not a list of strings', () => {
|
|
114
|
+
const result = builder.validate({
|
|
115
|
+
cloudFront: {
|
|
116
|
+
enable: true,
|
|
117
|
+
domainNames: 'api.example.com',
|
|
118
|
+
certificateArn: CERT_ARN,
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
expect(result.errors.join('\n')).toMatch(/domainNames/);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
describe('build()', () => {
|
|
126
|
+
it('puts a distribution in front of the HttpApi with caching disabled', async () => {
|
|
127
|
+
const result = await builder.build(
|
|
128
|
+
{ cloudFront: { enable: true } },
|
|
129
|
+
{}
|
|
130
|
+
);
|
|
131
|
+
const distribution = result.resources.FriggCloudFrontDistribution;
|
|
132
|
+
|
|
133
|
+
expect(distribution.Type).toBe('AWS::CloudFront::Distribution');
|
|
134
|
+
const config = distribution.Properties.DistributionConfig;
|
|
135
|
+
expect(config.Enabled).toBe(true);
|
|
136
|
+
expect(config.PriceClass).toBe('PriceClass_100');
|
|
137
|
+
expect(config.HttpVersion).toBe('http2and3');
|
|
138
|
+
|
|
139
|
+
expect(config.Origins).toHaveLength(1);
|
|
140
|
+
const [origin] = config.Origins;
|
|
141
|
+
expect(origin.DomainName).toEqual({
|
|
142
|
+
'Fn::Join': [
|
|
143
|
+
'',
|
|
144
|
+
[
|
|
145
|
+
{ Ref: 'HttpApi' },
|
|
146
|
+
'.execute-api.',
|
|
147
|
+
{ Ref: 'AWS::Region' },
|
|
148
|
+
'.amazonaws.com',
|
|
149
|
+
],
|
|
150
|
+
],
|
|
151
|
+
});
|
|
152
|
+
expect(origin.CustomOriginConfig).toEqual(
|
|
153
|
+
expect.objectContaining({
|
|
154
|
+
OriginProtocolPolicy: 'https-only',
|
|
155
|
+
OriginSSLProtocols: ['TLSv1.2'],
|
|
156
|
+
OriginReadTimeout: 30,
|
|
157
|
+
})
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
const behavior = config.DefaultCacheBehavior;
|
|
161
|
+
expect(behavior.TargetOriginId).toBe(origin.Id);
|
|
162
|
+
expect(behavior.ViewerProtocolPolicy).toBe('https-only');
|
|
163
|
+
expect(behavior.AllowedMethods).toEqual(
|
|
164
|
+
expect.arrayContaining([
|
|
165
|
+
'GET',
|
|
166
|
+
'HEAD',
|
|
167
|
+
'OPTIONS',
|
|
168
|
+
'PUT',
|
|
169
|
+
'PATCH',
|
|
170
|
+
'POST',
|
|
171
|
+
'DELETE',
|
|
172
|
+
])
|
|
173
|
+
);
|
|
174
|
+
expect(behavior.CachePolicyId).toBe(CACHING_DISABLED_POLICY_ID);
|
|
175
|
+
expect(behavior.OriginRequestPolicyId).toBe(
|
|
176
|
+
ALL_VIEWER_EXCEPT_HOST_HEADER_POLICY_ID
|
|
177
|
+
);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it('uses only the stack name as Comment, to stay within the 128-character limit', async () => {
|
|
181
|
+
const result = await builder.build({ cloudFront: { enable: true } }, {});
|
|
182
|
+
const config = result.resources.FriggCloudFrontDistribution.Properties.DistributionConfig;
|
|
183
|
+
|
|
184
|
+
// CloudFormation stack names are at most 128 characters.
|
|
185
|
+
expect(config.Comment).toBe('${self:service}-${self:provider.stage}');
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('uses the AWS managed policy ids for CachingDisabled and AllViewerExceptHostHeader', () => {
|
|
189
|
+
expect(CACHING_DISABLED_POLICY_ID).toBe(
|
|
190
|
+
'4135ea2d-6df8-44a3-9df3-4b5a84be39ad'
|
|
191
|
+
);
|
|
192
|
+
expect(ALL_VIEWER_EXCEPT_HOST_HEADER_POLICY_ID).toBe(
|
|
193
|
+
'b689b0a8-53d0-40ab-baf2-68738e2966ac'
|
|
194
|
+
);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('uses the default CloudFront certificate without a custom domain', async () => {
|
|
198
|
+
const result = await builder.build(
|
|
199
|
+
{ cloudFront: { enable: true } },
|
|
200
|
+
{}
|
|
201
|
+
);
|
|
202
|
+
const config =
|
|
203
|
+
result.resources.FriggCloudFrontDistribution.Properties
|
|
204
|
+
.DistributionConfig;
|
|
205
|
+
|
|
206
|
+
expect(config.ViewerCertificate).toEqual({
|
|
207
|
+
CloudFrontDefaultCertificate: true,
|
|
208
|
+
});
|
|
209
|
+
expect(config).not.toHaveProperty('Aliases');
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('uses the ACM certificate, SNI and TLS 1.2+ with a custom domain', async () => {
|
|
213
|
+
const result = await builder.build(
|
|
214
|
+
{
|
|
215
|
+
cloudFront: {
|
|
216
|
+
enable: true,
|
|
217
|
+
domainNames: ['api.example.com'],
|
|
218
|
+
certificateArn: CERT_ARN,
|
|
219
|
+
priceClass: 'PriceClass_200',
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
{}
|
|
223
|
+
);
|
|
224
|
+
const config =
|
|
225
|
+
result.resources.FriggCloudFrontDistribution.Properties
|
|
226
|
+
.DistributionConfig;
|
|
227
|
+
|
|
228
|
+
expect(config.Aliases).toEqual(['api.example.com']);
|
|
229
|
+
expect(config.PriceClass).toBe('PriceClass_200');
|
|
230
|
+
expect(config.ViewerCertificate).toEqual({
|
|
231
|
+
AcmCertificateArn: CERT_ARN,
|
|
232
|
+
SslSupportMethod: 'sni-only',
|
|
233
|
+
MinimumProtocolVersion: 'TLSv1.2_2021',
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it('exports the public URL and the distribution id as stack outputs', async () => {
|
|
238
|
+
const result = await builder.build(
|
|
239
|
+
{ cloudFront: { enable: true } },
|
|
240
|
+
{}
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
expect(result.outputs.FriggCloudFrontUrl.Value).toEqual({
|
|
244
|
+
'Fn::Join': [
|
|
245
|
+
'',
|
|
246
|
+
[
|
|
247
|
+
'https://',
|
|
248
|
+
{
|
|
249
|
+
'Fn::GetAtt': [
|
|
250
|
+
'FriggCloudFrontDistribution',
|
|
251
|
+
'DomainName',
|
|
252
|
+
],
|
|
253
|
+
},
|
|
254
|
+
],
|
|
255
|
+
],
|
|
256
|
+
});
|
|
257
|
+
expect(result.outputs.FriggCloudFrontDistributionId.Value).toEqual({
|
|
258
|
+
Ref: 'FriggCloudFrontDistribution',
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it('adds no IAM statements, functions or environment to the app', async () => {
|
|
263
|
+
const result = await builder.build(
|
|
264
|
+
{ cloudFront: { enable: true } },
|
|
265
|
+
{}
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
expect(result.iamStatements).toEqual([]);
|
|
269
|
+
expect(result.functions).toEqual({});
|
|
270
|
+
expect(result.environment).toEqual({});
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
});
|
|
@@ -33,11 +33,6 @@ const {
|
|
|
33
33
|
nestedNodeModulesExcludes,
|
|
34
34
|
} = require('../shared/utilities/nested-node-modules');
|
|
35
35
|
const { queueArnFromUrl } = require('../shared/utilities/sqs-queue-arn');
|
|
36
|
-
const {
|
|
37
|
-
declaredMaxConcurrency,
|
|
38
|
-
queueWorkerConcurrencySource,
|
|
39
|
-
queueWorkerMaximumConcurrency,
|
|
40
|
-
} = require('./queue-worker-concurrency');
|
|
41
36
|
const { bundledPrismaEngineExcludes } = require('../shared/lambda-architectures');
|
|
42
37
|
const {
|
|
43
38
|
INTEGRATION_QUEUE_MAX_RECEIVE_COUNT,
|
|
@@ -441,19 +436,12 @@ class IntegrationBuilder extends InfrastructureBuilder {
|
|
|
441
436
|
|
|
442
437
|
// Create Queue Worker function
|
|
443
438
|
const queueWorkerName = `${integrationName}QueueWorker`;
|
|
444
|
-
const queueWorkerReservedConcurrency = 20;
|
|
445
|
-
// ADR-049 section 6, 2a: the integration's queueWorker setting, else
|
|
446
|
-
// the modules' maxConcurrency, caps the whole queue worker.
|
|
447
|
-
const maximumConcurrency = queueWorkerMaximumConcurrency(
|
|
448
|
-
integration,
|
|
449
|
-
queueWorkerReservedConcurrency
|
|
450
|
-
);
|
|
451
439
|
result.functions[queueWorkerName] = {
|
|
452
440
|
handler: `node_modules/@friggframework/core/handlers/workers/integration-defined-workers.handlers.${integrationName}.queueWorker`,
|
|
453
441
|
skipEsbuild: true, // Nested exports in node_modules - skip esbuild bundling
|
|
454
442
|
package: functionPackageConfig,
|
|
455
443
|
...(usePrismaLayer && { layers: [{ Ref: 'PrismaLambdaLayer' }] }), // Queue workers need Prisma for database operations
|
|
456
|
-
reservedConcurrency:
|
|
444
|
+
reservedConcurrency: 20,
|
|
457
445
|
events: [
|
|
458
446
|
{
|
|
459
447
|
sqs: {
|
|
@@ -465,33 +453,12 @@ class IntegrationBuilder extends InfrastructureBuilder {
|
|
|
465
453
|
},
|
|
466
454
|
batchSize: 1,
|
|
467
455
|
functionResponseType: 'ReportBatchItemFailures',
|
|
468
|
-
...(maximumConcurrency !== undefined && {
|
|
469
|
-
maximumConcurrency,
|
|
470
|
-
}),
|
|
471
456
|
},
|
|
472
457
|
},
|
|
473
458
|
],
|
|
474
459
|
timeout: 900, // 15 minutes max for queue workers (Lambda maximum)
|
|
475
460
|
};
|
|
476
461
|
console.log(` ✓ Queue worker function defined`);
|
|
477
|
-
const concurrencySource = queueWorkerConcurrencySource(integration);
|
|
478
|
-
if (
|
|
479
|
-
maximumConcurrency === undefined &&
|
|
480
|
-
concurrencySource.value !== undefined
|
|
481
|
-
) {
|
|
482
|
-
console.log(
|
|
483
|
-
` ⚠ Queue worker maximumConcurrency ${concurrencySource.value} not set: it is not below the reserved concurrency of ${queueWorkerReservedConcurrency}`
|
|
484
|
-
);
|
|
485
|
-
}
|
|
486
|
-
if (maximumConcurrency !== undefined) {
|
|
487
|
-
console.log(
|
|
488
|
-
` ✓ Queue worker maximumConcurrency ${maximumConcurrency} for the whole queue (${
|
|
489
|
-
concurrencySource.source === 'integration'
|
|
490
|
-
? 'Definition.queueWorker.maximumConcurrency'
|
|
491
|
-
: `smallest module maxConcurrency ${declaredMaxConcurrency(integration)}; set Definition.queueWorker.maximumConcurrency to change or false to turn off`
|
|
492
|
-
})`
|
|
493
|
-
);
|
|
494
|
-
}
|
|
495
462
|
}
|
|
496
463
|
|
|
497
464
|
/**
|
|
@@ -393,92 +393,6 @@ describe('IntegrationBuilder', () => {
|
|
|
393
393
|
expect(result.functions.testQueueWorker.reservedConcurrency).toBe(20);
|
|
394
394
|
});
|
|
395
395
|
|
|
396
|
-
describe('maximumConcurrency from the modules (ADR-049 section 6, 2a)', () => {
|
|
397
|
-
const withModules = (...limits) => ({
|
|
398
|
-
integrations: [
|
|
399
|
-
{
|
|
400
|
-
Definition: {
|
|
401
|
-
name: 'test',
|
|
402
|
-
modules: Object.fromEntries(
|
|
403
|
-
limits.map((maxConcurrency, i) => [
|
|
404
|
-
`m${i}`,
|
|
405
|
-
{
|
|
406
|
-
definition: {
|
|
407
|
-
API: class {
|
|
408
|
-
static rateLimit =
|
|
409
|
-
maxConcurrency === undefined
|
|
410
|
-
? undefined
|
|
411
|
-
: { maxConcurrency };
|
|
412
|
-
},
|
|
413
|
-
},
|
|
414
|
-
},
|
|
415
|
-
])
|
|
416
|
-
),
|
|
417
|
-
},
|
|
418
|
-
},
|
|
419
|
-
],
|
|
420
|
-
});
|
|
421
|
-
const sqsOf = (result) =>
|
|
422
|
-
result.functions.testQueueWorker.events[0].sqs;
|
|
423
|
-
|
|
424
|
-
it('sets the smallest maxConcurrency of the modules', async () => {
|
|
425
|
-
const result = await integrationBuilder.build(
|
|
426
|
-
withModules(10, 5, undefined),
|
|
427
|
-
{}
|
|
428
|
-
);
|
|
429
|
-
expect(sqsOf(result).maximumConcurrency).toBe(5);
|
|
430
|
-
expect(result.functions.testQueueWorker.reservedConcurrency).toBe(20);
|
|
431
|
-
});
|
|
432
|
-
|
|
433
|
-
it('raises a value under 2 to the SQS minimum of 2', async () => {
|
|
434
|
-
const result = await integrationBuilder.build(withModules(1), {});
|
|
435
|
-
expect(sqsOf(result).maximumConcurrency).toBe(2);
|
|
436
|
-
});
|
|
437
|
-
|
|
438
|
-
it('sets nothing when no module declares maxConcurrency', async () => {
|
|
439
|
-
const result = await integrationBuilder.build(
|
|
440
|
-
withModules(undefined),
|
|
441
|
-
{}
|
|
442
|
-
);
|
|
443
|
-
expect(sqsOf(result)).not.toHaveProperty('maximumConcurrency');
|
|
444
|
-
});
|
|
445
|
-
|
|
446
|
-
it('sets nothing when the value is not below the reserved concurrency', async () => {
|
|
447
|
-
const result = await integrationBuilder.build(withModules(50), {});
|
|
448
|
-
expect(sqsOf(result)).not.toHaveProperty('maximumConcurrency');
|
|
449
|
-
});
|
|
450
|
-
|
|
451
|
-
const withSetting = (setting, ...limits) => {
|
|
452
|
-
const app = withModules(...limits);
|
|
453
|
-
app.integrations[0].Definition.queueWorker = {
|
|
454
|
-
maximumConcurrency: setting,
|
|
455
|
-
};
|
|
456
|
-
return app;
|
|
457
|
-
};
|
|
458
|
-
|
|
459
|
-
it('uses Definition.queueWorker.maximumConcurrency over the modules', async () => {
|
|
460
|
-
const result = await integrationBuilder.build(
|
|
461
|
-
withSetting(8, 3),
|
|
462
|
-
{}
|
|
463
|
-
);
|
|
464
|
-
expect(sqsOf(result).maximumConcurrency).toBe(8);
|
|
465
|
-
});
|
|
466
|
-
|
|
467
|
-
it('refuses a Definition.queueWorker.maximumConcurrency that is not an integer or false', async () => {
|
|
468
|
-
await expect(
|
|
469
|
-
integrationBuilder.build(withSetting('8', 3), {})
|
|
470
|
-
).rejects.toThrow('must be an integer from 2 to 1000, or false');
|
|
471
|
-
});
|
|
472
|
-
|
|
473
|
-
it('sets nothing when Definition.queueWorker.maximumConcurrency is false', async () => {
|
|
474
|
-
const result = await integrationBuilder.build(
|
|
475
|
-
withSetting(false, 3),
|
|
476
|
-
{}
|
|
477
|
-
);
|
|
478
|
-
expect(sqsOf(result)).not.toHaveProperty('maximumConcurrency');
|
|
479
|
-
});
|
|
480
|
-
});
|
|
481
|
-
|
|
482
396
|
it('should add queue URL to environment variables', async () => {
|
|
483
397
|
const appDefinition = {
|
|
484
398
|
integrations: [
|