-
Notifications
You must be signed in to change notification settings - Fork 0
/
sst.config.ts
98 lines (87 loc) · 3.59 KB
/
sst.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import * as lambda from 'aws-cdk-lib/aws-lambda';
import * as sst from 'sst/constructs';
import { SSTConfig } from 'sst';
import { Api } from './stacks/Api';
import { Auth } from './stacks/Auth';
import { Client } from './stacks/Client';
import { Core } from './stacks/Core';
import { AppSyncApi } from './stacks/AppSyncApi';
import { ServiceCatalog } from './stacks/ServiceCatalog';
import { ConnectionGateway } from './stacks/ConnectionGateway';
import { featureFlagIsEnabled } from './stacks/config/feature-flags';
import { Docs } from './stacks/Docs';
export default {
config() {
return {
name: 'virtual-lab-core',
region: 'us-east-1',
};
},
async stacks(app) {
if (
featureFlagIsEnabled({
featureFlag: 'READABLE_LOG_FORMAT',
components: ['Lambda Powertools Dev Logging'],
forceEnable: app.mode === 'dev',
})
) {
app.addDefaultFunctionEnv({ POWERTOOLS_DEV: 'true' });
}
const enableNewRelicLambdaInstrumentation = featureFlagIsEnabled({
featureFlag: 'NEW_RELIC_LAMBDA_INSTRUMENTATION',
components: ['New Relic Lambda Layer'],
forceDisable: app.mode === 'dev',
});
if (enableNewRelicLambdaInstrumentation) {
app.setDefaultFunctionProps((stack) => {
/**
* @see https://layers.newrelic-external.com/
*/
const newRelicLayer = lambda.LayerVersion.fromLayerVersionArn(
stack,
'NewRelicLayer',
'arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:69',
);
return {
layers: [newRelicLayer.layerVersionArn],
};
});
}
app.stack(Core);
app.stack(Auth);
app.stack(AppSyncApi);
app.stack(Api);
app.stack(Docs);
app.stack(ServiceCatalog);
app.stack(ConnectionGateway);
app.stack(Client);
if (enableNewRelicLambdaInstrumentation) {
await app.finish();
const newRelicAccountId = process.env.NEW_RELIC_ACCOUNT_ID;
const newRelicTrustedAccountKey = process.env.NEW_RELIC_TRUSTED_ACCOUNT_KEY;
const newRelicLicenseKey = process.env.NEW_RELIC_LICENSE_KEY;
if (!newRelicAccountId || !newRelicTrustedAccountKey || !newRelicLicenseKey) {
throw new Error(
'NEW_RELIC_ACCOUNT_ID and NEW_RELIC_TRUSTED_ACCOUNT_KEY must be set in the environment',
);
}
app.node.children.forEach((stack) => {
if (stack instanceof sst.Stack) {
stack.getAllFunctions().forEach((fn) => {
const cfnFunction = fn.node.defaultChild as lambda.CfnFunction;
if (cfnFunction.handler) {
fn.addEnvironment('NEW_RELIC_LAMBDA_HANDLER', cfnFunction.handler);
fn.addEnvironment('NEW_RELIC_ACCOUNT_ID', newRelicAccountId);
fn.addEnvironment(
'NEW_RELIC_TRUSTED_ACCOUNT_KEY',
newRelicTrustedAccountKey,
);
fn.addEnvironment('NEW_RELIC_LICENSE_KEY', newRelicLicenseKey);
}
cfnFunction.handler = 'newrelic-lambda-wrapper.handler';
});
}
});
}
},
} satisfies SSTConfig;