-
Notifications
You must be signed in to change notification settings - Fork 232
/
Copy pathparameter.ts
71 lines (66 loc) · 2.24 KB
/
parameter.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
import * as cdk from 'aws-cdk-lib';
import {
StackInput,
stackInputSchema,
ProcessedStackInput,
} from './lib/stack-input';
import { ModelConfiguration } from 'generative-ai-use-cases';
// Get parameters from CDK Context
const getContext = (app: cdk.App): StackInput => {
const params = stackInputSchema.parse(app.node.getAllContext());
return params;
};
// If you want to define parameters directly
const envs: Record<string, Partial<StackInput>> = {
// If you want to define an anonymous environment, uncomment the following and the content of cdk.json will be ignored.
// If you want to define an anonymous environment in parameter.ts, uncomment the following and the content of cdk.json will be ignored.
// '': {
// // Parameters for anonymous environment
// // If you want to override the default settings, add the following
// },
dev: {
// Parameters for development environment
},
staging: {
// Parameters for staging environment
},
prod: {
// Parameters for production environment
},
// If you need other environments, customize them as needed
};
// For backward compatibility, get parameters from CDK Context > parameter.ts
export const getParams = (app: cdk.App): ProcessedStackInput => {
// By default, get parameters from CDK Context
let params = getContext(app);
// If the env matches the ones defined in envs, use the parameters in envs instead of the ones in context
if (envs[params.env]) {
params = stackInputSchema.parse({
...envs[params.env],
env: params.env,
});
}
// Make the format of modelIds, imageGenerationModelIds consistent
const convertToModelConfiguration = (
models: (string | ModelConfiguration)[],
defaultRegion: string
): ModelConfiguration[] => {
return models.map((model) =>
typeof model === 'string'
? { modelId: model, region: defaultRegion }
: model
);
};
return {
...params,
modelIds: convertToModelConfiguration(params.modelIds, params.modelRegion),
imageGenerationModelIds: convertToModelConfiguration(
params.imageGenerationModelIds,
params.modelRegion
),
videoGenerationModelIds: convertToModelConfiguration(
params.videoGenerationModelIds,
params.modelRegion
),
};
};