-
Notifications
You must be signed in to change notification settings - Fork 128
/
EnvironmentVariablesService.ts
60 lines (44 loc) · 1.47 KB
/
EnvironmentVariablesService.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
import { ConfigService } from '.';
class EnvironmentVariablesService extends ConfigService {
// Reserved environment variables
private awsRegionVariable = 'AWS_REGION';
private functionNameVariable = 'AWS_LAMBDA_FUNCTION_NAME';
private functionVersionVariable = 'AWS_LAMBDA_FUNCTION_VERSION';
private memoryLimitInMBVariable = 'AWS_LAMBDA_FUNCTION_MEMORY_SIZE';
private xRayTraceIdVariable = '_X_AMZN_TRACE_ID';
public get(name: string): string {
return process.env[name]?.trim() || '';
}
public getAwsRegion(): string {
return this.get(this.awsRegionVariable);
}
public getCurrentEnvironment(): string {
return this.get(this.currentEnvironmentVariable);
}
public getFunctionMemory(): number {
const value = this.get(this.memoryLimitInMBVariable);
return Number(value);
}
public getFunctionName(): string {
return this.get(this.functionNameVariable);
}
public getFunctionVersion(): string {
return this.get(this.functionVersionVariable);
}
public getLogLevel(): string {
return this.get(this.logLevelVariable);
}
public getSampleRateValue(): number | undefined {
const value = this.get(this.sampleRateValueVariable);
return (value && value.length > 0) ? Number(value) : undefined;
}
public getServiceName(): string {
return this.get(this.serviceNameVariable);
}
public getXrayTraceId(): string {
return this.get(this.xRayTraceIdVariable);
}
}
export {
EnvironmentVariablesService,
};