@friggframework/devtools 2.0.0--canary.702.ef0dc8c.0 → 2.0.0--canary.667.a0620c7.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/README.md +0 -1
- package/frigg-cli/README.md +78 -76
- package/frigg-cli/__tests__/unit/commands/build.test.js +0 -3
- package/frigg-cli/__tests__/unit/commands/deploy.test.js +30 -27
- package/frigg-cli/__tests__/unit/commands/doctor.test.js +10 -6
- package/frigg-cli/__tests__/unit/commands/generate-iam.test.js +18 -0
- package/frigg-cli/__tests__/unit/commands/init.test.js +688 -0
- package/frigg-cli/__tests__/unit/commands/install.test.js +601 -341
- package/frigg-cli/__tests__/unit/commands/ui.test.js +31 -30
- package/frigg-cli/__tests__/unit/dependencies.test.js +6 -2
- package/frigg-cli/build-command/index.js +0 -6
- package/frigg-cli/deploy-command/index.js +0 -6
- package/frigg-cli/generate-command/index.js +1 -0
- package/frigg-cli/generate-iam-command.js +1 -0
- package/frigg-cli/index.js +10 -23
- package/frigg-cli/init-command/backend-first-handler.js +395 -531
- package/frigg-cli/init-command/deployment-modes.js +7 -0
- package/frigg-cli/init-command/index.js +82 -35
- package/frigg-cli/init-command/safe-path.js +58 -0
- package/frigg-cli/init-command/scaffold-dependencies.js +202 -0
- package/frigg-cli/install-command/app-definition.js +174 -0
- package/frigg-cli/install-command/commit-changes.js +40 -8
- package/frigg-cli/install-command/environment-variables.js +15 -0
- package/frigg-cli/install-command/index.js +96 -21
- package/frigg-cli/install-command/install-package.js +77 -4
- package/frigg-cli/install-command/integration-file.js +20 -11
- package/frigg-cli/install-command/resolve-module.js +69 -0
- package/frigg-cli/install-command/template.js +102 -75
- package/frigg-cli/install-command/validate-package.js +36 -4
- package/frigg-cli/package.json +1 -1
- package/frigg-cli/start-command/index.js +0 -4
- package/frigg-cli/start-command/start-command.test.js +0 -3
- package/frigg-cli/templates/backend/README.md +267 -0
- package/frigg-cli/templates/backend/env.example +20 -0
- package/frigg-cli/templates/backend/gitignore +10 -0
- package/frigg-cli/templates/backend/index.js +114 -0
- package/frigg-cli/templates/backend/infrastructure.js +20 -0
- package/frigg-cli/test/init-command.test.js +9 -2
- package/infrastructure/__tests__/management-api-gateway-routes.test.js +281 -0
- package/infrastructure/__tests__/postgres-config.test.js +241 -835
- package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +148 -0
- package/infrastructure/__tests__/template-generation.test.js +36 -8
- package/infrastructure/create-frigg-infrastructure.js +1 -4
- package/infrastructure/docs/POSTGRES-CONFIGURATION.md +118 -60
- package/infrastructure/domains/database/aurora-builder.js +13 -2
- package/infrastructure/domains/database/aurora-builder.test.js +22 -0
- package/infrastructure/domains/health/application/use-cases/__tests__/mismatch-analyzer-method-name.test.js +12 -8
- package/infrastructure/domains/health/application/use-cases/__tests__/repair-via-import-use-case.test.js +19 -7
- package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.test.js +12 -8
- package/infrastructure/domains/health/domain/services/__tests__/import-progress-monitor.test.js +17 -18
- package/infrastructure/domains/health/domain/services/__tests__/update-progress-monitor.test.js +12 -2
- package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-relationship-analysis.test.js +8 -1
- package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.test.js +4 -2
- package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.test.js +10 -0
- package/infrastructure/domains/networking/vpc-builder.js +18 -8
- package/infrastructure/domains/networking/vpc-builder.test.js +26 -12
- package/infrastructure/domains/security/iam-generator.js +112 -5
- package/infrastructure/domains/security/iam-generator.test.js +94 -0
- package/infrastructure/domains/shared/cloudformation-discovery.test.js +36 -6
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +26 -2
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +34 -1
- package/infrastructure/infrastructure-composer.test.js +268 -794
- package/infrastructure/scripts/build-prisma-layer.test.js +28 -7
- package/infrastructure/scripts/build-time-discovery.test.js +18 -3
- package/package.json +10 -8
- package/frigg-cli/__tests__/unit/commands/validate-wiring.test.js +0 -92
- package/frigg-cli/index.test.js +0 -158
- package/frigg-cli/validate-command/__tests__/init-validation.test.js +0 -63
- package/frigg-cli/validate-command/__tests__/integrations-checks.test.js +0 -133
- package/frigg-cli/validate-command/__tests__/validate-app-definition.test.js +0 -326
- package/frigg-cli/validate-command/__tests__/validate-command.test.js +0 -241
- package/frigg-cli/validate-command/__tests__/validate-module-command.test.js +0 -119
- package/frigg-cli/validate-command/checks/config.js +0 -468
- package/frigg-cli/validate-command/checks/integrations.js +0 -274
- package/frigg-cli/validate-command/fixtures/bad-module/index.js +0 -18
- package/frigg-cli/validate-command/fixtures/fathom-module/definition.js +0 -76
- package/frigg-cli/validate-command/fixtures/fathom-module/index.js +0 -6
- package/frigg-cli/validate-command/format-report.js +0 -60
- package/frigg-cli/validate-command/index.js +0 -151
- package/frigg-cli/validate-command/load-app-definition.js +0 -93
- package/frigg-cli/validate-command/load-module-definition.js +0 -64
- package/frigg-cli/validate-command/schema-issues.js +0 -154
- package/frigg-cli/validate-command/validate-app-definition.js +0 -60
- package/frigg-cli/validate-command/validate-module-definition.js +0 -46
- package/infrastructure/app-definition-schema-contract.test.js +0 -607
- package/infrastructure/create-frigg-infrastructure.test.js +0 -51
- package/infrastructure/integration.test.js +0 -381
|
@@ -313,4 +313,98 @@ describe('IAM Generator', () => {
|
|
|
313
313
|
expect(yaml).toContain('CredentialsSecretArn:');
|
|
314
314
|
});
|
|
315
315
|
});
|
|
316
|
+
|
|
317
|
+
describe("scoping to the app's own resources", () => {
|
|
318
|
+
const yaml = require('js-yaml');
|
|
319
|
+
const policyResources = (template, policy) =>
|
|
320
|
+
template.Resources[
|
|
321
|
+
policy
|
|
322
|
+
].Properties.PolicyDocument.Statement.flatMap((statement) =>
|
|
323
|
+
[].concat(statement.Resource)
|
|
324
|
+
).map((r) => (typeof r === 'string' ? r : r['Fn::Sub']));
|
|
325
|
+
|
|
326
|
+
// `frigg deploy` names everything after the service (Definition.name):
|
|
327
|
+
// stack my-app-prod, functions my-app-prod-auth, role
|
|
328
|
+
// my-app-prod-us-east-1-lambdaRole, queues my-app-internal-error-queue-prod
|
|
329
|
+
// and my-app-prod-DbMigrationQueue, layer my-app-prisma-prod, and
|
|
330
|
+
// CloudFormation-named topics, alarms and buckets prefixed my-app-prod.
|
|
331
|
+
const generate = (appDefinition) => {
|
|
332
|
+
const summary = getFeatureSummary(appDefinition);
|
|
333
|
+
return yaml.load(
|
|
334
|
+
generateIAMCloudFormation({
|
|
335
|
+
appName: summary.appName,
|
|
336
|
+
serviceName: summary.serviceName,
|
|
337
|
+
features: summary.features,
|
|
338
|
+
})
|
|
339
|
+
);
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
it('reports the service name osls deploys under', () => {
|
|
343
|
+
expect(getFeatureSummary({ name: 'my-app' }).serviceName).toBe(
|
|
344
|
+
'my-app'
|
|
345
|
+
);
|
|
346
|
+
expect(getFeatureSummary({}).serviceName).toBe('create-frigg-app');
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
it('lets an app whose name does not contain "frigg" deploy its stack and resources', () => {
|
|
350
|
+
const resources = policyResources(
|
|
351
|
+
generate({ name: 'my-app' }),
|
|
352
|
+
'FriggCoreDeploymentPolicy'
|
|
353
|
+
);
|
|
354
|
+
|
|
355
|
+
for (const expected of [
|
|
356
|
+
'arn:aws:cloudformation:*:${AWS::AccountId}:stack/*my-app*/*',
|
|
357
|
+
'arn:aws:lambda:*:${AWS::AccountId}:function:*my-app*',
|
|
358
|
+
'arn:aws:iam::${AWS::AccountId}:role/*my-app*',
|
|
359
|
+
'arn:aws:sqs:*:${AWS::AccountId}:*my-app*',
|
|
360
|
+
'arn:aws:sns:*:${AWS::AccountId}:*my-app*',
|
|
361
|
+
'arn:aws:logs:*:${AWS::AccountId}:log-group:/aws/lambda/*my-app*',
|
|
362
|
+
'arn:aws:logs:*:${AWS::AccountId}:log-group:/aws/lambda/*my-app*:*',
|
|
363
|
+
'arn:aws:cloudwatch:*:${AWS::AccountId}:alarm:*my-app*',
|
|
364
|
+
'arn:aws:lambda:*:${AWS::AccountId}:layer:*my-app*',
|
|
365
|
+
'arn:aws:lambda:*:${AWS::AccountId}:layer:*my-app*:*',
|
|
366
|
+
'arn:aws:s3:::*my-app*',
|
|
367
|
+
'arn:aws:s3:::*my-app*/*',
|
|
368
|
+
]) {
|
|
369
|
+
expect(resources).toContain(expected);
|
|
370
|
+
}
|
|
371
|
+
// Existing grants for frigg-named resources are kept.
|
|
372
|
+
expect(resources).toContain(
|
|
373
|
+
'arn:aws:lambda:*:${AWS::AccountId}:function:*frigg*'
|
|
374
|
+
);
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
it('matches S3 bucket names in lower case', () => {
|
|
378
|
+
const resources = policyResources(
|
|
379
|
+
generate({ name: 'MyApp' }),
|
|
380
|
+
'FriggCoreDeploymentPolicy'
|
|
381
|
+
);
|
|
382
|
+
expect(resources).toContain('arn:aws:s3:::*myapp*');
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
it('scopes the SSM parameter grant to the app too', () => {
|
|
386
|
+
const template = generate({
|
|
387
|
+
name: 'my-app',
|
|
388
|
+
ssm: { enable: true },
|
|
389
|
+
});
|
|
390
|
+
const resources = policyResources(template, 'FriggSSMPolicy');
|
|
391
|
+
expect(resources).toContain(
|
|
392
|
+
'arn:aws:ssm:*:${AWS::AccountId}:parameter/*my-app*'
|
|
393
|
+
);
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
it('does not duplicate grants for an app named frigg', () => {
|
|
397
|
+
const resources = policyResources(
|
|
398
|
+
generate({ name: 'frigg' }),
|
|
399
|
+
'FriggCoreDeploymentPolicy'
|
|
400
|
+
);
|
|
401
|
+
expect(
|
|
402
|
+
resources.filter(
|
|
403
|
+
(r) =>
|
|
404
|
+
r ===
|
|
405
|
+
'arn:aws:lambda:*:${AWS::AccountId}:function:*frigg*'
|
|
406
|
+
)
|
|
407
|
+
).toHaveLength(1);
|
|
408
|
+
});
|
|
409
|
+
});
|
|
316
410
|
});
|
|
@@ -164,7 +164,7 @@ describe('CloudFormationDiscovery', () => {
|
|
|
164
164
|
expect(result.routeTableId).toBe('rtb-123');
|
|
165
165
|
expect(result.vpcEndpointSecurityGroupId).toBe('sg-vpce-123');
|
|
166
166
|
expect(result.s3VpcEndpointId).toBe('vpce-s3-123');
|
|
167
|
-
expect(result.
|
|
167
|
+
expect(result.dynamodbVpcEndpointId).toBe('vpce-ddb-123');
|
|
168
168
|
expect(result.kmsVpcEndpointId).toBe('vpce-kms-123');
|
|
169
169
|
expect(result.secretsManagerVpcEndpointId).toBe('vpce-sm-123');
|
|
170
170
|
});
|
|
@@ -190,6 +190,9 @@ describe('CloudFormationDiscovery', () => {
|
|
|
190
190
|
|
|
191
191
|
expect(result).toEqual({
|
|
192
192
|
fromCloudFormationStack: true,
|
|
193
|
+
// _extractFromResources() initialises the structured endpoint map whenever
|
|
194
|
+
// the stack has resources (37a354e8)
|
|
195
|
+
vpcEndpoints: {},
|
|
193
196
|
stackName: 'test-stack',
|
|
194
197
|
auroraClusterId: 'test-cluster',
|
|
195
198
|
existingLogicalIds: ['FriggAuroraCluster'],
|
|
@@ -257,6 +260,9 @@ describe('CloudFormationDiscovery', () => {
|
|
|
257
260
|
|
|
258
261
|
expect(result).toEqual({
|
|
259
262
|
fromCloudFormationStack: true,
|
|
263
|
+
// _extractFromResources() initialises the structured endpoint map whenever
|
|
264
|
+
// the stack has resources (37a354e8)
|
|
265
|
+
vpcEndpoints: {},
|
|
260
266
|
stackName: 'test-stack',
|
|
261
267
|
migrationStatusBucket: 'test-migration-bucket',
|
|
262
268
|
existingLogicalIds: ['FriggMigrationStatusBucket'],
|
|
@@ -285,6 +291,9 @@ describe('CloudFormationDiscovery', () => {
|
|
|
285
291
|
|
|
286
292
|
expect(result).toEqual({
|
|
287
293
|
fromCloudFormationStack: true,
|
|
294
|
+
// _extractFromResources() initialises the structured endpoint map whenever
|
|
295
|
+
// the stack has resources (37a354e8)
|
|
296
|
+
vpcEndpoints: {},
|
|
288
297
|
stackName: 'test-stack',
|
|
289
298
|
migrationQueueUrl:
|
|
290
299
|
'https://sqs.us-east-1.amazonaws.com/123456789/test-queue',
|
|
@@ -313,6 +322,9 @@ describe('CloudFormationDiscovery', () => {
|
|
|
313
322
|
|
|
314
323
|
expect(result).toEqual({
|
|
315
324
|
fromCloudFormationStack: true,
|
|
325
|
+
// _extractFromResources() initialises the structured endpoint map whenever
|
|
326
|
+
// the stack has resources (37a354e8)
|
|
327
|
+
vpcEndpoints: {},
|
|
316
328
|
stackName: 'test-stack',
|
|
317
329
|
natGatewayId: 'nat-0123456789',
|
|
318
330
|
existingLogicalIds: ['FriggNatGateway'],
|
|
@@ -340,6 +352,9 @@ describe('CloudFormationDiscovery', () => {
|
|
|
340
352
|
|
|
341
353
|
expect(result).toEqual({
|
|
342
354
|
fromCloudFormationStack: true,
|
|
355
|
+
// _extractFromResources() initialises the structured endpoint map whenever
|
|
356
|
+
// the stack has resources (37a354e8)
|
|
357
|
+
vpcEndpoints: {},
|
|
343
358
|
stackName: 'test-stack',
|
|
344
359
|
defaultVpcId: 'vpc-037ec55fe87aec1e7',
|
|
345
360
|
existingLogicalIds: ['FriggVPC'],
|
|
@@ -378,6 +393,9 @@ describe('CloudFormationDiscovery', () => {
|
|
|
378
393
|
|
|
379
394
|
expect(result).toEqual({
|
|
380
395
|
fromCloudFormationStack: true,
|
|
396
|
+
// _extractFromResources() initialises the structured endpoint map whenever
|
|
397
|
+
// the stack has resources (37a354e8)
|
|
398
|
+
vpcEndpoints: {},
|
|
381
399
|
stackName: 'test-stack',
|
|
382
400
|
defaultVpcId: 'vpc-123', // VpcBuilder expects 'defaultVpcId'
|
|
383
401
|
defaultKmsKeyId: 'arn:aws:kms:us-east-1:123456789:key/abc',
|
|
@@ -406,6 +424,9 @@ describe('CloudFormationDiscovery', () => {
|
|
|
406
424
|
|
|
407
425
|
expect(result).toEqual({
|
|
408
426
|
fromCloudFormationStack: true,
|
|
427
|
+
// _extractFromResources() initialises the structured endpoint map whenever
|
|
428
|
+
// the stack has resources (37a354e8)
|
|
429
|
+
vpcEndpoints: {},
|
|
409
430
|
stackName: 'test-stack',
|
|
410
431
|
});
|
|
411
432
|
});
|
|
@@ -439,6 +460,11 @@ describe('CloudFormationDiscovery', () => {
|
|
|
439
460
|
SecurityGroups: [{ VpcId: 'vpc-123' }],
|
|
440
461
|
});
|
|
441
462
|
|
|
463
|
+
// Mock the VPC's default security group lookup (added in 37a354e8)
|
|
464
|
+
mockEC2Client.send.mockResolvedValueOnce({
|
|
465
|
+
SecurityGroups: [{ GroupId: 'sg-default-123' }],
|
|
466
|
+
});
|
|
467
|
+
|
|
442
468
|
// Mock subnet query
|
|
443
469
|
mockEC2Client.send.mockResolvedValueOnce({
|
|
444
470
|
Subnets: [
|
|
@@ -469,9 +495,11 @@ describe('CloudFormationDiscovery', () => {
|
|
|
469
495
|
|
|
470
496
|
const result = await cfDiscovery.discoverFromStack('test-stack');
|
|
471
497
|
|
|
498
|
+
expect(result.defaultVpcId).toBe('vpc-123');
|
|
499
|
+
expect(result.defaultSecurityGroupId).toBe('sg-default-123');
|
|
472
500
|
expect(result.privateSubnetId1).toBe('subnet-private-1');
|
|
473
501
|
expect(result.privateSubnetId2).toBe('subnet-private-2');
|
|
474
|
-
expect(mockEC2Client.send).toHaveBeenCalledTimes(
|
|
502
|
+
expect(mockEC2Client.send).toHaveBeenCalledTimes(3);
|
|
475
503
|
});
|
|
476
504
|
|
|
477
505
|
it('should handle EC2 subnet query errors gracefully', async () => {
|
|
@@ -739,7 +767,7 @@ describe('CloudFormationDiscovery', () => {
|
|
|
739
767
|
expect(result.vpcEndpoints.s3).toBe('vpce-0352ceac2124c14be');
|
|
740
768
|
expect(result.vpcEndpoints.dynamodb).toBe('vpce-0b06c4f631199ea68');
|
|
741
769
|
expect(result.s3VpcEndpointId).toBe('vpce-0352ceac2124c14be');
|
|
742
|
-
expect(result.
|
|
770
|
+
expect(result.dynamodbVpcEndpointId).toBe('vpce-0b06c4f631199ea68');
|
|
743
771
|
|
|
744
772
|
// Verify NO VPC/KMS resources (they're external)
|
|
745
773
|
expect(result.defaultVpcId).toBeUndefined();
|
|
@@ -776,7 +804,7 @@ describe('CloudFormationDiscovery', () => {
|
|
|
776
804
|
expect(result.vpcEndpoints.s3).toBe('vpce-legacy-s3');
|
|
777
805
|
expect(result.vpcEndpoints.dynamodb).toBe('vpce-legacy-ddb');
|
|
778
806
|
expect(result.s3VpcEndpointId).toBe('vpce-legacy-s3');
|
|
779
|
-
expect(result.
|
|
807
|
+
expect(result.dynamodbVpcEndpointId).toBe('vpce-legacy-ddb');
|
|
780
808
|
});
|
|
781
809
|
|
|
782
810
|
it('should extract FriggLambdaSecurityGroup from stack', async () => {
|
|
@@ -807,7 +835,9 @@ describe('CloudFormationDiscovery', () => {
|
|
|
807
835
|
|
|
808
836
|
// Lambda security group should be extracted
|
|
809
837
|
expect(result.lambdaSecurityGroupId).toBe('sg-01002240c6a446202');
|
|
810
|
-
|
|
838
|
+
// The Lambda SG must not masquerade as the VPC's default SG
|
|
839
|
+
// (defaultSecurityGroupId is only ever the VPC default; see 37a354e8).
|
|
840
|
+
expect(result.defaultSecurityGroupId).toBeUndefined();
|
|
811
841
|
expect(result.existingLogicalIds).toContain(
|
|
812
842
|
'FriggLambdaSecurityGroup'
|
|
813
843
|
);
|
|
@@ -899,7 +929,7 @@ describe('CloudFormationDiscovery', () => {
|
|
|
899
929
|
|
|
900
930
|
describe('existingLogicalIds tracking', () => {
|
|
901
931
|
it('should track OLD VPC endpoint logical IDs (VPCEndpointS3 pattern) for backwards compatibility', async () => {
|
|
902
|
-
// CRITICAL:
|
|
932
|
+
// CRITICAL: Older production stacks use the OLD naming convention
|
|
903
933
|
const mockStack = {
|
|
904
934
|
StackName: 'create-frigg-app-production',
|
|
905
935
|
Outputs: [],
|
|
@@ -286,6 +286,11 @@ function createBaseDefinition(
|
|
|
286
286
|
...(usePrismaLayer && { layers: [{ Ref: 'PrismaLambdaLayer' }] }),
|
|
287
287
|
skipEsbuild: true, // Handlers in node_modules don't need bundling
|
|
288
288
|
package: skipEsbuildPackageConfig,
|
|
289
|
+
// Every path prefix the core integration router
|
|
290
|
+
// (createIntegrationRouter) registers must be routed here;
|
|
291
|
+
// HTTP API has no implicit catch-all, so an unlisted prefix
|
|
292
|
+
// 404s at the gateway before Express sees it. Guarded by
|
|
293
|
+
// __tests__/management-api-gateway-routes.test.js.
|
|
289
294
|
events: [
|
|
290
295
|
{ httpApi: { path: '/api/integrations', method: 'ANY' } },
|
|
291
296
|
{
|
|
@@ -295,6 +300,20 @@ function createBaseDefinition(
|
|
|
295
300
|
},
|
|
296
301
|
},
|
|
297
302
|
{ httpApi: { path: '/api/authorize', method: 'ANY' } },
|
|
303
|
+
{ httpApi: { path: '/api/entity', method: 'ANY' } },
|
|
304
|
+
{
|
|
305
|
+
httpApi: {
|
|
306
|
+
path: '/api/entity/{proxy+}',
|
|
307
|
+
method: 'ANY',
|
|
308
|
+
},
|
|
309
|
+
},
|
|
310
|
+
{ httpApi: { path: '/api/entities', method: 'ANY' } },
|
|
311
|
+
{
|
|
312
|
+
httpApi: {
|
|
313
|
+
path: '/api/entities/{proxy+}',
|
|
314
|
+
method: 'ANY',
|
|
315
|
+
},
|
|
316
|
+
},
|
|
298
317
|
],
|
|
299
318
|
},
|
|
300
319
|
user: {
|
|
@@ -383,12 +402,18 @@ function createBaseDefinition(
|
|
|
383
402
|
},
|
|
384
403
|
},
|
|
385
404
|
},
|
|
405
|
+
// The functions above use `httpApi` events, so osls creates
|
|
406
|
+
// an HTTP API (API Gateway v2, logical ID HttpApi) with only
|
|
407
|
+
// the `$default` stage. HTTP APIs publish `5xx`, not the REST
|
|
408
|
+
// API metric `5XXError`, and the ApiId dimension identifies
|
|
409
|
+
// this API (a Stage dimension would have to be `$default`).
|
|
410
|
+
// https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-metrics.html
|
|
386
411
|
ApiGatewayAlarm5xx: {
|
|
387
412
|
Type: 'AWS::CloudWatch::Alarm',
|
|
388
413
|
Properties: {
|
|
389
414
|
AlarmDescription: 'API Gateway 5xx Errors',
|
|
390
415
|
Namespace: 'AWS/ApiGateway',
|
|
391
|
-
MetricName: '
|
|
416
|
+
MetricName: '5xx',
|
|
392
417
|
Statistic: 'Sum',
|
|
393
418
|
Threshold: 0,
|
|
394
419
|
ComparisonOperator: 'GreaterThanThreshold',
|
|
@@ -397,7 +422,6 @@ function createBaseDefinition(
|
|
|
397
422
|
AlarmActions: [{ Ref: 'InternalErrorBridgeTopic' }],
|
|
398
423
|
Dimensions: [
|
|
399
424
|
{ Name: 'ApiId', Value: { Ref: 'HttpApi' } },
|
|
400
|
-
{ Name: 'Stage', Value: '${self:provider.stage}' },
|
|
401
425
|
],
|
|
402
426
|
},
|
|
403
427
|
},
|
|
@@ -94,7 +94,19 @@ describe('Base Definition Factory', () => {
|
|
|
94
94
|
|
|
95
95
|
expect(result.functions.auth.handler).toBe('node_modules/@friggframework/core/handlers/routers/auth.handler');
|
|
96
96
|
expect(result.functions.auth.layers).toEqual([{ Ref: 'PrismaLambdaLayer' }]);
|
|
97
|
-
expect(
|
|
97
|
+
expect(
|
|
98
|
+
result.functions.auth.events.map(
|
|
99
|
+
(e) => `${e.httpApi.method} ${e.httpApi.path}`
|
|
100
|
+
)
|
|
101
|
+
).toEqual([
|
|
102
|
+
'ANY /api/integrations',
|
|
103
|
+
'ANY /api/integrations/{proxy+}',
|
|
104
|
+
'ANY /api/authorize',
|
|
105
|
+
'ANY /api/entity',
|
|
106
|
+
'ANY /api/entity/{proxy+}',
|
|
107
|
+
'ANY /api/entities',
|
|
108
|
+
'ANY /api/entities/{proxy+}',
|
|
109
|
+
]);
|
|
98
110
|
});
|
|
99
111
|
|
|
100
112
|
it('should NOT include legacy dbMigrate function', () => {
|
|
@@ -121,6 +133,27 @@ describe('Base Definition Factory', () => {
|
|
|
121
133
|
expect(result.resources.Resources.ApiGatewayAlarm5xx).toBeDefined();
|
|
122
134
|
});
|
|
123
135
|
|
|
136
|
+
it('alarms on the HTTP API 5xx metric of the API osls creates', () => {
|
|
137
|
+
// The Frigg functions use `httpApi` events, so osls creates an
|
|
138
|
+
// API Gateway v2 HTTP API (logical ID HttpApi) with only the
|
|
139
|
+
// `$default` stage. HTTP APIs publish `5xx` (REST APIs publish
|
|
140
|
+
// `5XXError`) with the ApiId dimension; a Stage dimension set to
|
|
141
|
+
// the deploy stage name would never match `$default`.
|
|
142
|
+
const result = createBaseDefinition({}, {}, {});
|
|
143
|
+
const usesHttpApi = Object.values(result.functions).some((fn) =>
|
|
144
|
+
(fn.events || []).some((event) => event.httpApi)
|
|
145
|
+
);
|
|
146
|
+
expect(usesHttpApi).toBe(true);
|
|
147
|
+
|
|
148
|
+
const alarm = result.resources.Resources.ApiGatewayAlarm5xx;
|
|
149
|
+
expect(alarm.Properties).toMatchObject({
|
|
150
|
+
Namespace: 'AWS/ApiGateway',
|
|
151
|
+
MetricName: '5xx',
|
|
152
|
+
Dimensions: [{ Name: 'ApiId', Value: { Ref: 'HttpApi' } }],
|
|
153
|
+
AlarmActions: [{ Ref: 'InternalErrorBridgeTopic' }],
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
124
157
|
it('should include base IAM permissions', () => {
|
|
125
158
|
const result = createBaseDefinition({}, {}, {});
|
|
126
159
|
|