repo_name string | dataset string | owner string | lang string | func_name string | code string | docstring string | url string | sha string |
|---|---|---|---|---|---|---|---|---|
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | ApplicationAssetBundler.constructor | private constructor() {} | /**
* Because the the class is a factory class, the constructor private. Call {@link ApplicationAssetBundler.assetBundlerFactory()} instead
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/asset-options-factory.ts#L73-L73 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | ApplicationAssetBundler.assetBundlerFactory | public static assetBundlerFactory(): BundlerAssetOptionsFactory {
if (ApplicationAssetBundler._assetFactory === undefined) {
this._assetFactory = new BundlerAssetOptionsFactory();
}
return this._assetFactory;
} | /**
* A static method to return the Singleton instance of {@link AssetOptionsFactory} class
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/asset-options-factory.ts#L78-L84 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | CdkJsonContextAssetOptions.options | public options(construct: IConstruct, entry: string, assetHash?: string): s3_assets.AssetOptions {
entry = path.resolve(entry);
return {
...(assetHash && { assetHash: assetHash, assetHashType: cdk.AssetHashType.CUSTOM }),
bundling: {
image: COMMERCIAL_REGION_LAMBDA_PYTHON_RUNTIME.bundlingImage,
user: 'root',
command: new CdkJsonDockerBuildTemplate(CDK_PYTHON_BUNDLER).bundle(construct, entry, '/asset-output'),
securityOpt: 'no-new-privileges:true',
network: 'host',
local: util.getLocalBundler(new CdkJsonLocalBuildTemplate(CDK_PYTHON_BUNDLER), construct, entry)
} as cdk.BundlingOptions,
exclude: DEPENDENCY_EXCLUDES
} as s3_assets.AssetOptions;
} | /**
* An implementation of AssetOptions method to build artifacts.
*
* @param assetHash
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/cdk-json.ts#L34-L48 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | CdkJsonLocalBuildTemplate.readContextProperty | protected readContextProperty(construct: IConstruct, buildStage: string): string[] {
const buildTemplate = construct.node.tryGetContext(this.buildTemplateKey);
let templateSteps: string[] = [];
if (
!Object.hasOwn(buildTemplate, LOCAL_BUILD_VAR) &&
Object.hasOwn(buildTemplate[LOCAL_BUILD_VAR], buildStage)
) {
templateSteps = buildTemplate[LOCAL_BUILD_VAR][buildStage];
}
if (!Array.isArray(templateSteps)) {
throw new Error(`Incorrect build commands for ${this.buildTemplateKey} in stage ${buildStage}`);
}
return templateSteps;
} | /**
* A utility method to read build steps from cdk json
*
* @param construct
* @param key - key of the template definition in the context definition
* @param buildStage - pre, post, build or unit-test stage within the template definition
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/cdk-json.ts#L139-L154 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | CdkJsonDockerBuildTemplate.readContextProperty | protected readContextProperty(construct: IConstruct, buildStage: string): string[] {
const buildTemplate = construct.node.tryGetContext(this.buildTemplateKey);
let templateSteps: string[] = [];
if (
!Object.hasOwn(buildTemplate, DOCKER_BUILD_VAR) &&
Object.hasOwn(buildTemplate[DOCKER_BUILD_VAR], buildStage)
) {
templateSteps = buildTemplate[DOCKER_BUILD_VAR][buildStage];
}
templateSteps = buildTemplate[DOCKER_BUILD_VAR][buildStage];
if (!Array.isArray(templateSteps)) {
throw new Error(`Incorrect build commands for ${this.buildTemplateKey} in stage ${buildStage}`);
}
return templateSteps;
} | /**
* A utility method to read build steps from cdk json
*
* @param construct
* @param key - key of the template definition in the context definition
* @param buildStage - pre, post, build or unit-test stage within the template definition
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/cdk-json.ts#L169-L185 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | CdkJsonDockerBuildTemplate.bundle | public bundle(construct: IConstruct, moduleName: string, outputDir: string): string[] {
return ['bash', '-c', super.bundle(construct, moduleName, outputDir).join(' && ')];
} | /**
* bundler implementation for docker builds
*
* @param moduleName
* @param outputDir
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/cdk-json.ts#L194-L196 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | JavascriptLayerAssetOptions.initializeOptions | protected initializeOptions() {
this.dockerBuild = new JavascriptLayerDockerBuild();
this.localBuild = new JavascriptLayerLocalBuild();
} | /**
* Method to initialize build templates for TS builds
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/javascript-layer.ts#L14-L17 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | JavascriptLayerDockerBuild.postBuild | protected postBuild(moduleName: string, outputDir: string): string[] {
return [
`mkdir -p ${outputDir}/nodejs/node_modules`,
`cp -au /asset-input/node_modules/* ${outputDir}/nodejs/node_modules/`
];
} | /**
* Copy assets to output directory post build
*
* @param moduleName
* @param outputDir
* @param construct
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/javascript-layer.ts#L32-L37 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | JavascriptLayerLocalBuild.postBuild | protected postBuild(moduleName: string, outputDir: string): string[] {
return [
`mkdir -p ${outputDir}/nodejs/node_modules`,
`cp -R ${moduleName}/node_modules/* ${outputDir}/nodejs/node_modules/` // for local build there is no post build steps.
];
} | /**
* Copy assets to output directory post build
* @param moduleName
* @param outputDir
* @param construct
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/javascript-layer.ts#L51-L56 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | JavascriptAssetOptions.initializeOptions | protected initializeOptions() {
this.dockerBuild = new JavascriptDockerBuild();
this.localBuild = new JavascriptLocalBuild();
} | /**
* Method to initialize the build templates for JS builds
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/javascript.ts#L36-L39 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | JavascriptDockerBuild.preBuild | protected preBuild(moduleName: string, outputDir: string): string[] {
return [
`echo \"local bundling failed for ${moduleName} and hence building with Docker image\"`,
'rm -fr /asset-input/node_modules'
];
} | /**
* pre-build steps for Nodejs docker build
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/javascript.ts#L64-L69 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | JavascriptDockerBuild.build | protected build(moduleName: string, outputDir: string): string[] {
return ['npm install', 'rm -fr ./node_modules', 'npm ci --omit=dev'];
} | /**
* Build steps for docker build
* @param outputDir
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/javascript.ts#L75-L77 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | JavascriptDockerBuild.cleanup | protected cleanup(moduleName: string, outputDir: string): string[] {
return [`rm -fr ${outputDir}/.coverage`];
} | /**
* post-build steps for local bundling
*
* @param outputDir
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/javascript.ts#L89-L91 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | JavascriptDockerBuild.unitTest | protected unitTest(moduleName: string, outputDir: string): string[] {
return ['echo "Executing unit tests"', 'npm install', 'npm run test'];
} | /**
* Unit test execution
*
* @param outputDir
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/javascript.ts#L99-L101 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | JavascriptLocalBuild.build | protected build(moduleName: string, outputDir: string): string[] {
return ['npm ci --omit=dev'];
} | /**
* build steps for local bundling
*
* @param outputDir
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/javascript.ts#L114-L116 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | JavascriptLocalBuild.preBuild | protected preBuild(moduleName: string, outputDir: string): string[] {
return [`echo local bundling ${moduleName}`, `cd ${moduleName}`, 'rm -fr node_modules'];
} | /**
* pre-build steps for local bundling
*
* @param outputDir
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/javascript.ts#L124-L126 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | JavascriptLocalBuild.unitTest | protected unitTest(moduleName: string, outputDir: string): string[] {
return ['echo "Executing unit tests"', `cd ${moduleName}`, 'npm install', 'npm run test'];
} | /**
* unit test execution for local bundling
*
* @param outputDir
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/javascript.ts#L148-L150 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | LangChainLayerAssetOptions.options | public options(
construct: IConstruct,
entry: string,
packagingOptions?: AdditionalInstallArguments,
assetHash?: string
): s3_assets.AssetOptions {
const pipOptions = packagingOptions as PipInstallArguments;
// if pipOptions is not provided use default values for platform
const resolvedPipOptions = resolvePipOptions(pipOptions);
this.dockerBuild = new LangChainLayerDockerBuild(resolvedPipOptions);
this.localBuild = new LangChainLayerLocalBuild(resolvedPipOptions);
return super.options(construct, entry, packagingOptions, assetHash);
} | /**
* An implementation of AssetOptions method to build artifacts.
*
* @param assetHash
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/langchain-layer.ts#L37-L49 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | LangChainLayerDockerBuild.postBuild | protected postBuild(moduleName: string, outputDir: string): string[] {
const commandList: string[] = [];
if (process.env.SKIP_PRE_BUILD?.toLowerCase() === 'true') {
commandList.push('python3 -m pip install poetry --upgrade');
}
commandList.push(
`poetry run pip install --python-version ${this.evaluatedPipOptions.pythonVersion} --platform ${this.evaluatedPipOptions.platform} --implementation ${this.evaluatedPipOptions.implementation} --only-binary=${this.evaluatedPipOptions.onlyBinary} -t ${outputDir}/python/ dist/*.whl`
);
return commandList;
} | /**
* Install the dependencies in the output directory
*
* @param moduleName
* @param outputDir
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/langchain-layer.ts#L70-L80 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | LangchainPythonVersionAssetOptions.options | public options(
construct: IConstruct,
entry: string,
packagingOptions?: AdditionalInstallArguments,
assetHash?: string
): s3_assets.AssetOptions {
entry = path.resolve(entry);
const pipOptions = packagingOptions as PipInstallArguments;
this.dockerBuild = new LangChainPythonVersionDockerBuild(pipOptions);
return {
...(assetHash && { assetHash: assetHash, assetHashType: cdk.AssetHashType.CUSTOM }),
bundling: {
image: LANGCHAIN_LAMBDA_PYTHON_RUNTIME.bundlingImage,
user: 'root',
command: this.dockerBuild.bundle(construct, entry, '/asset-output'),
securityOpt: 'no-new-privileges:true',
network: 'host',
local: getLocalBundler(this.localBuild, construct, entry)
} as cdk.BundlingOptions,
exclude: DEPENDENCY_EXCLUDES
} as s3_assets.AssetOptions;
} | /**
* An implementation of AssetOptions method to build artifacts.
*
* @param assetHash
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/langchain-py-version.ts#L27-L49 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | PythonLayerAssetOptions.initializeOptions | protected initializeOptions() {
this.dockerBuild = new PythonLayerDockerBuild();
this.localBuild = new PythonLayerLocalBuild();
} | /**
* Method to initialize the build templates for JS builds
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/python-layer.ts#L14-L17 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | PythonLayerDockerBuild.build | protected build(moduleName: string, outputDir: string): string[] {
return ['poetry build', 'poetry install --only main'];
} | /**
* For python build steps include copying the artifacts into the output directory and installing module
* dependencies
*
* @param outputDir
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/python-layer.ts#L31-L33 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | PythonLayerDockerBuild.postBuild | protected postBuild(moduleName: string, outputDir: string): string[] {
const commandList: string[] = [];
if (process.env.SKIP_PRE_BUILD?.toLowerCase() === 'true') {
commandList.push('python3 -m pip install poetry --upgrade');
}
commandList.push(`poetry run pip install -t ${outputDir}/python/ dist/*.whl`);
return commandList;
} | /**
* Install the dependencies in the output directory
*
* @param moduleName
* @param outputDir
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/python-layer.ts#L42-L50 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | PythonAssetOptions.initializeOptions | protected initializeOptions() {
this.dockerBuild = new PythonDockerBuild();
this.localBuild = new PythonLocalBuild();
} | /**
* Method to initialize the build templates for JS builds
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/python.ts#L49-L52 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | PythonAssetOptions.options | public options(
construct: IConstruct,
entry: string,
packagingOptions?: AdditionalInstallArguments,
assetHash?: string
): s3_assets.AssetOptions {
entry = path.resolve(entry);
return {
...(assetHash && { assetHash: assetHash, assetHashType: cdk.AssetHashType.CUSTOM }),
bundling: {
image: COMMERCIAL_REGION_LAMBDA_PYTHON_RUNTIME.bundlingImage,
user: 'root',
command: this.dockerBuild.bundle(construct, entry, '/asset-output'),
securityOpt: 'no-new-privileges:true',
network: 'host',
local: getLocalBundler(this.localBuild, construct, entry)
} as cdk.BundlingOptions,
exclude: DEPENDENCY_EXCLUDES
} as s3_assets.AssetOptions;
} | /**
* An implementation of AssetOptions method to build artifacts.
*
* @param assetHash
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/python.ts#L60-L79 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | PythonDockerBuild.preBuild | protected preBuild(moduleName: string, outputDir: string): string[] {
return [
`echo "local bundling failed for ${moduleName} and hence building with Docker image"`,
'rm -fr .venv*',
'rm -fr dist',
'rm -fr .coverage',
'rm -fr coverage',
'python3 -m pip install poetry --upgrade'
];
} | /**
* For python pre-build steps include creating the output directory and deleting any virtual environments created
*
* @param outputDir
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/python.ts#L92-L101 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | PythonDockerBuild.build | protected build(moduleName: string, outputDir: string): string[] {
return ['python3 -m pip install poetry --upgrade', 'poetry build', 'poetry install --only main'];
} | /**
* For python build steps include copying the artifacts into the output directory and installing module
* dependencies
*
* @param outputDir
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/python.ts#L110-L112 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | PythonDockerBuild.unitTest | protected unitTest(moduleName: string, outputDir: string): string[] {
return getUnitTestSteps();
} | /**
* Unit test steps to
*
* @param outputDir
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/python.ts#L120-L122 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | PythonDockerBuild.postBuild | protected postBuild(moduleName: string, outputDir: string): string[] {
const commandList: string[] = [];
if (process.env.SKIP_PRE_BUILD?.toLowerCase() === 'true') {
commandList.push('python3 -m pip install poetry --upgrade');
}
commandList.push(
...[`cp -au /asset-input/* ${outputDir}/`, `poetry run pip install -t ${outputDir} dist/*.whl`]
);
return commandList;
} | /**
* Copying assets
*
* @param moduleName
* @param outputDir
* @param construct
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/python.ts#L132-L141 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | PythonDockerBuild.cleanup | protected cleanup(moduleName: string, outputDir: string): string[] {
return [`find ${outputDir} | grep -E "(/__pycache__$|\.pyc$|\.pyo$|\.coverage$)" | xargs rm -rf`];
} | /**
* As post-build cleanup, remove anything that is not required for packaging.
*
* @param outputDir
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/python.ts#L149-L151 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | PythonLocalBuild.preBuild | protected preBuild(moduleName: string, outputDir: string): string[] {
return [
`echo local bundling ${moduleName}`,
`cd ${moduleName}`,
'rm -fr .venv*',
'rm -fr dist',
'rm -fr coverage',
'rm -fr .coverage',
'python3 -m venv .venv',
'. .venv/bin/activate',
'python3 -m pip install poetry --upgrade'
];
} | /**
* Pre-build steps for local build template
*
* @param outputDir
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/python.ts#L164-L176 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | PythonLocalBuild.build | protected build(moduleName: string, outputDir: string): string[] {
return ['poetry build', 'poetry install --only main'];
} | /**
* For python build steps include copying the artifacts into the output directory and installing module
* dependencies
*
* @param outputDir
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/python.ts#L185-L187 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | PythonLocalBuild.postBuild | protected postBuild(moduleName: string, outputDir: string): string[] {
return [
`cd ${moduleName}`,
'python3 -m pip install poetry --upgrade',
`poetry run pip install -t ${outputDir} dist/*.whl`
];
} | /**
* Execute statements post build
*
* @param moduleName
* @param outputDir
* @param construct
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/python.ts#L197-L203 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | PythonLocalBuild.cleanup | protected cleanup(moduleName: string, outputDir: string): string[] {
return [
'deactivate',
`find ${outputDir} | grep -E "(/__pycache__$|\.pyc$|\.pyo$|.coverage$|dist$|.venv*$)" | xargs rm -rf`,
`rm -fr ${outputDir}/requirements.txt`
];
} | /**
* Clean up files and directories post build
*
* @param moduleName
* @param outputDir
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/python.ts#L212-L218 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | PythonLocalBuild.unitTest | protected unitTest(moduleName: string, outputDir: string): string[] {
return [`cd ${moduleName}`].concat(getUnitTestSteps());
} | /**
* Execute unit test
*
* @param moduleName
* @param outputDir
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/python.ts#L227-L229 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | ReactjsAssetOptions.initializeOptions | protected initializeOptions() {
this.dockerBuild = new ReactjsDockerBuild();
this.localBuild = new ReactjsLocalBuild();
} | /**
* Method to initialize build templates for TS builds
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/reactjs.ts#L14-L17 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | ReactjsDockerBuild.build | protected build(moduleName: string, outputDir: string): string[] {
return [`mkdir -p build/`, 'npm install', 'npm run build'];
} | /**
* Build steps for docker build
* @param outputDir
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/reactjs.ts#L28-L30 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | ReactjsLocalBuild.build | protected build(moduleName: string, outputDir: string): string[] {
return ['mkdir -p build', 'npm install', 'npm run build'];
} | /**
* build steps for local bundling
*
* @param outputDir
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/reactjs.ts#L47-L49 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | TypescriptLayerAssetOptions.initializeOptions | protected initializeOptions() {
this.dockerBuild = new TypescriptLayerDockerBuild();
this.localBuild = new TypescriptLayerLocalBuild();
} | /**
* Method to initialize build templates for TS builds
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/typescript-layer.ts#L16-L19 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | TypescriptLayerDockerBuild.build | protected build(moduleName: string, outputDir: string): string[] {
return [
`mkdir -p ${outputDir}/nodejs`,
'npm install',
'npm run build',
'rm -fr ./node_modules',
'npm ci --omit=dev'
];
} | /**
* Build steps for docker build
* @param outputDir
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/typescript-layer.ts#L30-L38 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | TypescriptLayerDockerBuild.postBuild | protected postBuild(moduleName: string, outputDir: string, construct?: IConstruct | undefined): string[] {
const moduleFolderName = path.basename(moduleName);
return [
`mkdir -p ${outputDir}/nodejs`,
`cp -au /asset-input/node_modules ${outputDir}/nodejs/`,
`mkdir -p ${outputDir}/nodejs/node_modules/${moduleFolderName}`,
`cp -au /asset-input/dist/* ${outputDir}/nodejs/node_modules/${moduleFolderName}/`
];
} | /**
* Copy assets to output directory post build
*
* @param moduleName
* @param outputDir
* @param construct
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/typescript-layer.ts#L48-L57 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | TypescriptLayerLocalBuild.postBuild | protected postBuild(moduleName: string, outputDir: string): string[] {
const moduleFolderName = path.basename(moduleName);
return [
`mkdir -p ${outputDir}/nodejs`,
`cp -R ${moduleName}/node_modules ${outputDir}/nodejs/`,
`mkdir -p ${outputDir}/nodejs/node_modules/${moduleFolderName}`,
`cp -R ${moduleName}/dist/* ${outputDir}/nodejs/node_modules/${moduleFolderName}/` // for local build there is no post build steps.
];
} | /**
* Copy assets to output directory post build
* @param moduleName
* @param outputDir
* @param construct
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/typescript-layer.ts#L71-L79 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | TypescriptAssetOptions.initializeOptions | protected initializeOptions() {
this.dockerBuild = new TypescriptDockerBuild();
this.localBuild = new TypescriptLocalBuild();
} | /**
* Method to initialize build templates for TS builds
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/typscript.ts#L15-L18 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | TypescriptDockerBuild.build | protected build(moduleName: string, outputDir: string): string[] {
return ['npm install', 'npm run build', 'rm -fr ./node_modules', 'npm ci --omit=dev'];
} | /**
* build steps for local bundling
*
* @param outputDir
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/typscript.ts#L29-L31 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | TypescriptDockerBuild.postBuild | protected postBuild(moduleName: string, outputDir: string, construct?: IConstruct | undefined): string[] {
return [
`mkdir -p ${outputDir}/`,
`cp -au /asset-input/node_modules ${outputDir}/`,
`cp -au /asset-input/dist/* ${outputDir}/`
];
} | /**
* Copy assets to output directory post build
*
* @param moduleName
* @param outputDir
* @param construct
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/typscript.ts#L41-L47 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | TypescriptLocalBuild.postBuild | protected postBuild(moduleName: string, outputDir: string): string[] {
return [
`mkdir -p ${outputDir}`,
`cp -R ${moduleName}/node_modules ${outputDir}/`,
`cp -R ${moduleName}/dist/* ${outputDir}/` // for local build there is no post build steps.
];
} | /**
* Copy assets to output directory post build
* @param moduleName
* @param outputDir
* @param construct
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/typscript.ts#L71-L77 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | TypescriptLocalBuild.preBuild | protected preBuild(moduleName: string, outputDir: string): string[] {
const commandList = super.preBuild(moduleName, outputDir);
commandList.push('rm -fr dist');
return commandList;
} | /**
* pre-build steps for local bundling
*
* @param outputDir
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/framework/bundler/runtime/typscript.ts#L85-L89 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | KendraKnowledgeBase.createKendraIndex | private createKendraIndex(props: KendraKnowledgeBaseParameters) {
const kendraProps = {
capacityUnits: {
queryCapacityUnits: props.queryCapacityUnits ?? 0,
storageCapacityUnits: props.storageCapacityUnits ?? 0
},
description: `Kendra index which provides a knowledge base for the Chat use case.`,
edition: props.kendraIndexEdition,
name: `${props.kendraIndexName}-${this.useCaseUUID}`,
roleArn: this.kendraKnowledgeBaseRole.roleArn,
serverSideEncryptionConfiguration: {
kmsKeyId: this.kendraKMSKey.keyId
}
} as kendra.CfnIndexProps;
// we do not want the Kendra index being deleted when a use case is deleted or updated to a new index.
const kendraKnowledgeBaseIndex = new kendra.CfnIndex(this, 'KendraKnowledgeBase', kendraProps);
kendraKnowledgeBaseIndex.applyRemovalPolicy(cdk.RemovalPolicy.RETAIN);
return kendraKnowledgeBaseIndex;
} | /**
* Handles creation of Kendra index with given properties
*
* @param props properties as passed from constructor
* @returns CfnIndex, the created Kendra index
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/search/kendra-knowledge-base.ts#L155-L174 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | KendraKnowledgeBase.createKendraIAMRole | private createKendraIAMRole(): iam.Role {
const kendraRole = new iam.Role(this, 'KendraRole', {
assumedBy: new iam.ServicePrincipal('kendra.amazonaws.com')
});
kendraRole.addToPolicy(
new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
actions: ['cloudwatch:PutMetricData'],
resources: ['*'],
conditions: { StringEquals: { 'cloudwatch:namespace': 'AWS/Kendra' } }
})
);
kendraRole.addToPolicy(
new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
actions: ['logs:DescribeLogGroups'],
resources: ['*']
})
);
kendraRole.addToPolicy(
new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
actions: ['logs:CreateLogGroup'],
resources: [
`arn:${cdk.Aws.PARTITION}:logs:${cdk.Aws.REGION}:${cdk.Aws.ACCOUNT_ID}:log-group:/aws/kendra/*`
]
})
);
kendraRole.addToPolicy(
new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
actions: ['logs:DescribeLogStreams', 'logs:CreateLogStream', 'logs:PutLogEvents'],
resources: [
`arn:${cdk.Aws.PARTITION}:logs:${cdk.Aws.REGION}:${cdk.Aws.ACCOUNT_ID}:log-group:/aws/kendra/*:log-stream:*`
]
})
);
const kendraPolicy = kendraRole.node.tryFindChild('DefaultPolicy') as iam.Policy;
// since the Kendra index is retained, the role and policy are as well
kendraRole.applyRemovalPolicy(cdk.RemovalPolicy.RETAIN);
kendraPolicy.applyRemovalPolicy(cdk.RemovalPolicy.RETAIN);
return kendraRole;
} | /**
* Creates an IAM role which will be assigned to the Kendra index, allowing it to perform logging functions
*
* @returns the IAM role
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/search/kendra-knowledge-base.ts#L181-L230 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | DynamoDBChatStorage.createDynamoDBTables | private createDynamoDBTables(stackParams: DynamoDBChatStorageParameters) {
this.conversationTable = new dynamodb.Table(this, 'ConversationTable', {
encryption: dynamodb.TableEncryption.AWS_MANAGED,
billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
partitionKey: {
name: DynamoDBAttributes.CONVERSATION_TABLE_PARTITION_KEY,
type: dynamodb.AttributeType.STRING
},
sortKey: {
name: DynamoDBAttributes.CONVERSATION_TABLE_SORT_KEY,
type: dynamodb.AttributeType.STRING
},
timeToLiveAttribute: DynamoDBAttributes.TIME_TO_LIVE,
removalPolicy: cdk.RemovalPolicy.DESTROY
});
this.modelInfoStorage = new UseCaseModelInfoStorage(this, 'ModelInfoStorage', {
existingModelInfoTableName: stackParams.existingModelInfoTableName,
customResourceLambdaArn: this.customResourceLambdaArn,
customResourceRoleArn: this.customResourceLambdaRoleArn
});
} | /**
* Handles creation of DynamoDB table with given props
*
* @param stackParams properties as passed from constructor
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/storage/chat-storage-stack.ts#L89-L110 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | UIInfrastructureBuilder.constructor | constructor(props: UIInfrastructureBuilderProps) {
this.uiAssetFolder = props.uiAssetFolder;
this.deployWebApp = props.deployWebApp;
} | /**
* Constructor sets the uiAssetFolderPath property.
*
* @param props - UIInfrastructureBuilderProps object
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/ui/ui-infrastructure-builder.ts#L58-L61 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | UIInfrastructureBuilder.createDistribution | public createDistribution(scope: Construct, id: string, props: cdk.NestedStackProps) {
this.cloudFrontDistributionStack = new UIDistribution(scope, id, props);
const deployWebAppDistributionCondition = this.getOrCreateDeployWebAppCondition(scope);
(this.cloudFrontDistributionStack.node.defaultChild as cdk.CfnResource).cfnOptions.condition =
deployWebAppDistributionCondition;
return this.cloudFrontDistributionStack;
} | /**
* Creates a UI distribution using the UIDistribution nested stack.
*
* @param scope - Construct scope
* @param id - Stack id
* @param props - NestedStackProps
* @returns UIDistribution nested stack
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/ui/ui-infrastructure-builder.ts#L71-L80 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | UIInfrastructureBuilder.createUIAssetsCustomResource | public createUIAssetsCustomResource(scope: Construct, id: string, props: cdk.NestedStackProps) {
switch (this.uiAssetFolder) {
case UIAssetFolders.DEPLOYMENT_PLATFORM:
this.copyUIAssetsStack = new CopyDeploymentUIAssets(scope, id, props);
break;
case UIAssetFolders.CHAT:
this.copyUIAssetsStack = new CopyUseCaseUIAssets(scope, id, props);
break;
default:
throw new Error('Invalid UI asset folder');
}
const copyWebAssetsCondition = this.getOrCreateDeployWebAppCondition(scope);
(this.copyUIAssetsStack.node.defaultChild as cdk.CfnResource).cfnOptions.condition = copyWebAssetsCondition;
return this.copyUIAssetsStack;
} | /**
* Creates a custom resource to copy UI assets using the CopyUIAssets nested stack.
*
* @param scope - Construct scope
* @param id - Stack id
* @param props - NestedStackProps
* @returns CopyUIAssets nested stack
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/ui/ui-infrastructure-builder.ts#L90-L107 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | UIInfrastructureBuilder.getOrCreateDeployWebAppCondition | private getOrCreateDeployWebAppCondition(scope: Construct): cdk.CfnCondition {
if (this.deployWebAppCondition) {
return this.deployWebAppCondition;
}
this.deployWebAppCondition = new cdk.CfnCondition(
cdk.Stack.of(scope),
'DeployWebAppUIInfrastructureCondition',
{
expression: cdk.Fn.conditionEquals(this.deployWebApp, 'Yes')
}
);
return this.deployWebAppCondition;
} | /**
* Gets or creates the deploy web app condition resource.
*
* Checks if a condition was already created, and if not, initializes a new
* CfnCondition resource with an expression that checks if `deployWebApp` equals
* "yes". This condition controls whether the web app deployment proceeds.
*
* @param scope - The construct scope for the condition resource
* @returns The CfnCondition resource
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/ui/ui-infrastructure-builder.ts#L119-L132 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | UIInfrastructureBuilder.getCloudFrontUrlWithCondition | public getCloudFrontUrlWithCondition(): string {
return cdk.Fn.conditionIf(
this.deployWebAppCondition.logicalId,
`https://${this.cloudFrontDistributionStack.cloudFrontDistribution.domainName}`,
cdk.Aws.NO_VALUE
).toString();
} | /**
* Generates a URL for the CloudFront distribution
*
* This method returns a URL for the CloudFront distribution configured in this stack.
* It constructs the URL by prepending "https://" to the domain name of the distribution.
*
* @returns A string containing the CloudFront distribution URL
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/ui/ui-infrastructure-builder.ts#L142-L148 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | UIInfrastructureBuilder.getCloudFrontUrlWithoutCondition | public getCloudFrontUrlWithoutCondition(): string {
return `https://${this.cloudFrontDistributionStack.cloudFrontDistribution.domainName}`;
} | /**
* Generates a URL for the CloudFront distribution
*
* This method returns a URL for the CloudFront distribution configured in this stack.
* It constructs the URL by prepending "https://" to the domain name of the distribution.
*
* @returns A string containing the CloudFront distribution URL
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/ui/ui-infrastructure-builder.ts#L158-L160 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | UseCaseManagement.createVpcConfigForLambda | protected createVpcConfigForLambda(lambdaFunction: lambda.Function) {
const cfnLambdaFunction = lambdaFunction.node.defaultChild as lambda.CfnFunction;
cfnLambdaFunction.vpcConfig = cdk.Fn.conditionIf(
this.deployVPCCondition.logicalId,
{
SubnetIds: this.stackParameters.existingPrivateSubnetIds,
SecurityGroupIds: this.stackParameters.existingSecurityGroupIds
} as lambda.CfnFunction.VpcConfigProperty,
cdk.Aws.NO_VALUE
);
} | /**
* Method to add vpc configuration to lambda functions
*
* @param lambdaFunction
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/use-case-management/management-stack.ts#L528-L538 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | AppRegistry.visit | public visit(node: IConstruct): void {
if (node instanceof cdk.Stack) {
if (!node.nested) {
// parent stack
if (!this.application.get(node.stackId)) {
this.createAppForAppRegistry(node);
}
const stack = node;
this.application.get(node.stackId)!.associateApplicationWithStack(stack);
if (!this.attributeGroup) {
this.createAttributeGroup(node);
}
this.addTagsforApplication(node);
} else {
if (!this.application.get(node.nestedStackParent!.stackId)) {
this.createAppForAppRegistry(node.nestedStackParent!);
}
const nestedStack = node;
// prettier-ignore
new CfnResourceAssociation(
nestedStack,
`ResourceAssociation${hashValues(cdk.Names.nodeUniqueId(nestedStack.node))}`,
{
application: this.application.get(node.nestedStackParent!.stackId)!.applicationId,
resource: node.stackId,
resourceType: 'CFN_STACK'
}
);
(nestedStack.node.defaultChild as cdk.CfnResource).addDependency(
this.application.get(node.nestedStackParent!.stackId)!.node.defaultChild as cdk.CfnResource
);
}
}
} | /**
* Method invoked as a `Visitor` pattern to inject aspects during cdk synthesis
*
* @param node
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/utils/app-registry-aspects.ts#L90-L126 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | AppRegistry.createAppForAppRegistry | private createAppForAppRegistry(stack: cdk.Stack): void {
this.application.set(
stack.stackId,
new appreg.Application(stack, `RegistrySetup`, {
applicationName: this.applicationNameValue,
description: `Service Catalog application to track and manage all your resources for the solution ${this.solutionName}`
})
);
} | /**
* Method to initialize an Application in AppRegistry service
*
* @returns - Instance of AppRegistry's Application class
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/utils/app-registry-aspects.ts#L133-L141 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | AppRegistry.addTagsforApplication | private addTagsforApplication(node: cdk.Stack): void {
if (!this.application.get(node.stackId)) {
this.createAppForAppRegistry(node);
}
cdk.Tags.of(this.application.get(node.stackId)!).add('Solutions:SolutionID', this.solutionID);
cdk.Tags.of(this.application.get(node.stackId)!).add('Solutions:SolutionName', this.solutionName);
cdk.Tags.of(this.application.get(node.stackId)!).add('Solutions:SolutionVersion', this.solutionVersion);
cdk.Tags.of(this.application.get(node.stackId)!).add('Solutions:ApplicationType', this.applicationType);
} | /**
* Method to add tags to the AppRegistry's Application instance
*
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/utils/app-registry-aspects.ts#L151-L160 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | AppRegistry.createAttributeGroup | private createAttributeGroup(node: cdk.Stack): void {
if (!this.application.get(node.stackId)) {
this.createAppForAppRegistry(node);
}
this.attributeGroup = new appreg.AttributeGroup(node, `AppAttributes`, {
attributeGroupName: `AttrGrp-${cdk.Aws.STACK_NAME}`,
description: 'Attributes for Solutions Metadata',
attributes: {
applicationType: this.applicationType,
version: this.solutionVersion,
solutionID: this.solutionID,
solutionName: this.solutionName
}
});
this.attributeGroup.associateWith(this.application.get(node.stackId)!);
} | /**
* Method to create AttributeGroup to be associated with the Application's instance in AppRegistry
*
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/utils/app-registry-aspects.ts#L166-L181 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | LambdaAspects.addCWMetricsPolicy | private addCWMetricsPolicy(lambda: lambda.Function) {
if (!this.customMetricsPolicy) {
this.customMetricsPolicy = new Map();
}
const stack = cdk.Stack.of(lambda);
let metricsPolicy = this.customMetricsPolicy.get(stack.stackId);
if (metricsPolicy === undefined) {
metricsPolicy = new iam.Policy(stack, 'CustomMetricsPolicy', {
statements: [
new iam.PolicyStatement({
actions: ['cloudwatch:PutMetricData'],
effect: iam.Effect.ALLOW,
resources: ['*'],
conditions: {
StringEquals: {
'cloudwatch:namespace': [
CloudWatchNamespace.API_GATEWAY,
CloudWatchNamespace.AWS_KENDRA,
CloudWatchNamespace.AWS_COGNITO,
CloudWatchNamespace.LANGCHAIN_LLM
]
}
}
})
]
});
this.customMetricsPolicy.set(stack.stackId, metricsPolicy);
NagSuppressions.addResourceSuppressions(metricsPolicy, [
{
id: 'AwsSolutions-IAM5',
reason: 'This policy allows put metric data to CloudWatch. The policy is restricted using policy conditions.',
appliesTo: ['Resource::*']
}
]);
}
metricsPolicy.attachToRole(lambda.role!);
} | /**
* Method to add policy to put custom metrics to CloudWatch
*
* @param lambda
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/utils/lambda-aspect.ts#L83-L124 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | LambdaAspects.addLayersForPythonLambda | private addLayersForPythonLambda(node: cdk.aws_lambda.Function, solutionID: string, solutionVersion: string) {
node.addLayers(this.getOrCreatePythonUserAgent(node));
node.addEnvironment(
'AWS_SDK_USER_AGENT',
`{ "user_agent_extra": "AWSSOLUTION/${solutionID}/${solutionVersion}" }`
);
console.log(node.node.metadata);
/**
* checks if metadata to attach specific LLM libraries is present in the CDK definition of the
* lambda function. Because of Lambda's size limitation, it is not possible to attach both
* boto3 and LLM layers. Hence LLM Lambdas will rely on Lambda provided runtime version of
* Python SDK and will not bundle the boto3 SDK layer unless explicitly requested via the tag
*/
if (this.checkIfAdditionalLLMLayersRequired(node)) {
const lambdaMetadata = (node.node.defaultChild as lambda.CfnFunction).cfnOptions.metadata!;
const additionalLLMLayersList = lambdaMetadata[ADDITIONAL_LLM_LIBRARIES].split(',');
for (const layer of additionalLLMLayersList) {
switch (layer) {
case LLM_LIBRARY_LAYER_TYPES.LANGCHAIN_LIB_LAYER: {
node.addLayers(this.getOrCreateLangchainLayer(node));
break;
}
case LLM_LIBRARY_LAYER_TYPES.BOTO3_LIB_LAYER: {
node.addLayers(this.getOrCreateBoto3LibLayer(node));
break;
}
default: {
throw new Error('No valid library types provided');
}
}
}
} else {
node.addLayers(this.getOrCreateBoto3LibLayer(node));
}
} | /**
* Method to add layers for lambdas with python runtimes. This method has an additional check if the
* lambda function includes LLM libraries, it will not attach boto3 layer to restrict unpacked lambda size
* during deployment, implying that LLM lambda functions will rely on the AWS Lambda provided Python SDK
* versions
*
* @param node - the lambda Function construct currently visited (in context)
* @param solutionID
* @param solutionVersion
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/utils/lambda-aspect.ts#L136-L170 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | LambdaAspects.addLayersForNodejsLambda | private addLayersForNodejsLambda(node: cdk.aws_lambda.Function, solutionID: any, solutionVersion: any) {
node.addLayers(this.getOrCreateNodeUserAgent(node), this.getOrCreateAwsNodeSdkLibLayer(node));
node.addEnvironment(
'AWS_SDK_USER_AGENT',
`{ "customUserAgent": [["AWSSOLUTION/${solutionID}/${solutionVersion}"]] }`
);
node.addEnvironment('AWS_NODEJS_CONNECTION_REUSE_ENABLED', '1');
} | /**
* Method to add layers for Nodejs lambda
*
* @param node - the lambda Function construct currently visited (in context)
* @param solutionID
* @param solutionVersion
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/utils/lambda-aspect.ts#L179-L186 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | LambdaAspects.getOrCreateNodeUserAgent | private getOrCreateNodeUserAgent(node: Construct): lambda.LayerVersion {
const stackId = this.getStackIdFromNode(node);
if (this.nodejsUserAgentLayer.get(stackId) === undefined) {
this.nodejsUserAgentLayer.set(
stackId,
new TSUserAgentLayer(this.getConstructToCreateLayer(node), 'NodeUserAgentLayer', {
entry: '../lambda/layers/aws-node-user-agent-config',
description: 'This layer configures AWS Node SDK initialization to send user-agent information',
compatibleRuntimes: [GOV_CLOUD_REGION_LAMBDA_NODE_RUNTIME, COMMERCIAL_REGION_LAMBDA_NODE_RUNTIME]
})
);
}
return this.nodejsUserAgentLayer.get(stackId)!;
} | /**
* @returns Node runtime compatible LayerVersion for user-agent
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/utils/lambda-aspect.ts#L191-L205 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | LambdaAspects.getOrCreatePythonUserAgent | private getOrCreatePythonUserAgent(node: Construct): lambda.LayerVersion {
const stackId = this.getStackIdFromNode(node);
if (this.pythonUserAgentLayer.get(stackId) === undefined) {
this.pythonUserAgentLayer.set(
stackId,
new PythonUserAgentLayer(this.getConstructToCreateLayer(node), 'PythonUserAgentLayer', {
entry: '../lambda/layers/custom_boto3_init',
description: 'This layer configures AWS Python SDK initialization to send user-agent information',
compatibleRuntimes: pythonCompatibleRuntimes
})
);
}
return this.pythonUserAgentLayer.get(stackId)!;
} | /**
* This method checks if the layer definition exists. If not then creates a new one.
*
* @returns Python runtime compatible LayerVersion for user-agent
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/utils/lambda-aspect.ts#L212-L226 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | LambdaAspects.getOrCreateAwsNodeSdkLibLayer | private getOrCreateAwsNodeSdkLibLayer(node: Construct): lambda.LayerVersion {
const stackId = this.getStackIdFromNode(node);
if (this.awsNodeSdkLibLayer.get(stackId) === undefined) {
this.awsNodeSdkLibLayer.set(
stackId,
new AwsNodeSdkLibLayer(this.getConstructToCreateLayer(node), 'AwsNodeSdkLayer', {
entry: '../lambda/layers/aws-sdk-lib',
description: 'AWS Javascript SDK v3 to be bundled with lambda functions as a layer',
compatibleRuntimes: [GOV_CLOUD_REGION_LAMBDA_NODE_RUNTIME, COMMERCIAL_REGION_LAMBDA_NODE_RUNTIME]
})
);
}
return this.awsNodeSdkLibLayer.get(stackId)!;
} | /**
* This method checks if the layer defition exists. If not then creates a new one.
*
* @returns Lambda LayerVersion for AWS Node SDK
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/utils/lambda-aspect.ts#L233-L247 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | LambdaAspects.getOrCreateBoto3LibLayer | private getOrCreateBoto3LibLayer(node: Construct): lambda.LayerVersion {
const stackId = this.getStackIdFromNode(node);
if (this.boto3SdkLibLayer.get(stackId) === undefined) {
this.boto3SdkLibLayer.set(
stackId,
new Boto3SdkLibLayer(this.getConstructToCreateLayer(node), 'Boto3Layer', {
entry: '../lambda/layers/aws_boto3',
description: 'Boto3 layer to be bundled with python lambda functions',
compatibleRuntimes: pythonCompatibleRuntimes
})
);
}
return this.boto3SdkLibLayer.get(stackId)!;
} | /**
* This method checks if the layer definition exists. If not then creates a new one.
*
* @returns returns a LayerVersion for Boto3 library
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/utils/lambda-aspect.ts#L254-L268 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | LambdaAspects.getOrCreateLangchainLayer | private getOrCreateLangchainLayer(node: Construct): lambda.LayerVersion {
const stackId = this.getStackIdFromNode(node);
if (this.pythonLangchainLayer.get(stackId) === undefined) {
const pipInstallArgs = new PipInstallArguments();
pipInstallArgs.pythonVersion = LANGCHAIN_LAMBDA_PYTHON_RUNTIME.name.replace('python', '');
pipInstallArgs.platform = PYTHON_PIP_BUILD_PLATFORM;
this.pythonLangchainLayer.set(
stackId,
new PythonLangchainLayer(this.getConstructToCreateLayer(node), 'LangchainLayer', {
entry: '../lambda/layers/langchain',
description:
'This layer configures the LangChain python package to be bundled with python lambda functions',
compatibleRuntimes: pythonCompatibleRuntimes,
pipOptions: pipInstallArgs
})
);
}
return this.pythonLangchainLayer.get(stackId)!;
} | /**
* This method checks if the layer definition exists. If not then creates a new one.
*
* @returns Python runtime compatible LayerVersion for LangChain with all its required packages
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/utils/lambda-aspect.ts#L275-L294 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | LambdaAspects.getConstructToCreateLayer | private getConstructToCreateLayer(node: Construct) {
let construct: Construct;
if (cdk.Stack.of(node).nested) {
construct = cdk.Stack.of(cdk.Stack.of(node).nestedStackParent!);
} else {
construct = cdk.Stack.of(node);
}
return construct;
} | /**
* Get the construct of the stack to create the layer. If the construct is nested then get the construct of the parent
* stack.
*
* @param node
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/utils/lambda-aspect.ts#L303-L311 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | LambdaAspects.checkIfAdditionalLLMLayersRequired | private checkIfAdditionalLLMLayersRequired(node: lambda.Function): boolean {
// using escape hatches as there is no way to check if the metadata is present
const lambdaMetadata = (node.node.defaultChild as lambda.CfnFunction).cfnOptions.metadata;
if (lambdaMetadata && lambdaMetadata[ADDITIONAL_LLM_LIBRARIES]) {
return true;
}
return false;
} | /**
* Iterates through the lambda construct metadata (if present) in a lambda function node to check if the
* 'AttachLangchainLayer' metadata has a value of true or false.
* @param node lambda function node from template
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/utils/lambda-aspect.ts#L318-L326 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | LambdaAspects.getStackIdFromNode | private getStackIdFromNode(node: Construct): string {
const stackId = cdk.Stack.of(node).nestedStackParent
? cdk.Stack.of(node).nestedStackParent!.stackId
: cdk.Stack.of(node).stackId;
return stackId;
} | /**
* Method to get stack ID from node (Construct object)
*
* @param node
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/utils/lambda-aspect.ts#L334-L340 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | LambdaRuntimeCommandFactory.constructor | constructor(deployPartitionCondition: cdk.CfnCondition) {
this.lambdaRuntimeCommandMap = new Map<lambda.RuntimeFamily, LambdaRuntimeCommand>();
this.lambdaRuntimeCommandMap.set(
lambda.RuntimeFamily.PYTHON,
new PythonRuntimeCommand(deployPartitionCondition)
);
this.lambdaRuntimeCommandMap.set(
lambda.RuntimeFamily.NODEJS,
new NodejsRuntimeCommand(deployPartitionCondition)
);
} | /**
*
* @param deployPartitionCondition : The CfnCondition to check if the aws partition (govcloud vs non-govcloud)
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/utils/lambda-runtimes.ts#L79-L89 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | LambdaRuntimeCommandFactory.getRuntimeCommand | public getRuntimeCommand(runtimeFamily: lambda.RuntimeFamily): LambdaRuntimeCommand {
const lambdaRuntimeCommand = this.lambdaRuntimeCommandMap.get(runtimeFamily);
if (!lambdaRuntimeCommand) {
throw new Error('Runtime family not supported');
}
return lambdaRuntimeCommand;
} | /**
* Factory method to get the Lambda runtime based on the lambda runtime family
*
* @param runtimeFamily
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/utils/lambda-runtimes.ts#L97-L105 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | BedrockAgentVPC.getCompatibleAzs | protected getCompatibleAzs(): string[] {
const getCompatibleAZsCustomResource = new cdk.CustomResource(this, 'GetCompatibleAZs', {
resourceType: 'Custom::GetCompatibleAZs',
serviceToken: this.customResourceLambdaArn,
properties: {
Resource: 'GET_COMPATIBLE_AZS',
REQUIRED_SERVICE_NAMES: cdk.Fn.join(',', [
`com.amazonaws.${cdk.Aws.REGION}.lambda`, // useful placeholder for a service which should be in all AZs for a region
`com.amazonaws.${cdk.Aws.REGION}.bedrock-agent-runtime`,
`com.amazonaws.${cdk.Aws.REGION}.bedrock-agent`
]),
MAX_AZS: 2
}
});
const customResourceLambdaRole = iam.Role.fromRoleArn(
this,
'DescribeVpcEndpointServicesCustomResourceRole',
this.customResourceLambdaRoleArn
);
const describeVpcEndpointServicesPolicy = new iam.Policy(this, 'DescribeVpcEndpointServicesPolicy', {
statements: [
new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
actions: ['ec2:DescribeVpcEndpointServices'],
resources: ['*']
})
]
});
describeVpcEndpointServicesPolicy.attachToRole(customResourceLambdaRole);
getCompatibleAZsCustomResource.node.addDependency(describeVpcEndpointServicesPolicy);
// cfnag suppressions
NagSuppressions.addResourceSuppressions(describeVpcEndpointServicesPolicy, [
{
id: 'AwsSolutions-IAM5',
reason: 'Must specify * for the specified action',
appliesTo: ['Resource::*']
}
]);
// gets returned as comma separated string, so we parse into a string[]
return cdk.Fn.split(',', getCompatibleAZsCustomResource.getAttString('CompatibleAZs'), 2);
} | /**
* This method overrides the default implementation to choose AZs based on bedrock-agent and
* bedrock-agent-runtime endpoints availability
*
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/vpc/bedrock-agent-vpc.ts#L99-L142 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | BedrockAgentVPC.getStackType | public getStackType(): string {
return 'bedrock-agents';
} | /**
* Returns the stack type that the VPC is being used in. This could be use-case, deployment
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/vpc/bedrock-agent-vpc.ts#L147-L149 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | BedrockUseCaseVPC.getStackType | public getStackType(): string {
return 'bedrock-use-case';
} | /**
* Returns the stack type that the VPC is being used in. This could be use-case, deployment
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/vpc/bedrock-vpc.ts#L62-L64 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | CustomVPC.createServiceEndpoints | protected createServiceEndpoints() {
const ddbEndpoint: ec2.GatewayVpcEndpoint = this.vpc.addGatewayEndpoint('DDBEndpoint', {
service: ec2.GatewayVpcEndpointAwsService.DYNAMODB,
subnets: [{ subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS }]
});
ddbEndpoint.addToPolicy(
new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
principals: [new iam.AnyPrincipal()], // NOSONAR - policy is on vpc endpoint, user principal is not known - typescript:S6270
//Also this is an endpoint policy, to perform the actions on dynamodb, the lambda still requires requisite permissions.
resources: [`arn:${cdk.Aws.PARTITION}:dynamodb:${cdk.Aws.REGION}:${cdk.Aws.ACCOUNT_ID}:table/*`],
actions: [
'dynamodb:BatchGetItem',
'dynamodb:BatchWriteItem',
'dynamodb:ConditionCheckItem',
'dynamodb:DeleteItem',
'dynamodb:DescribeTable',
'dynamodb:GetItem',
'dynamodb:GetRecords',
'dynamodb:GetShardIterator',
'dynamodb:PutItem',
'dynamodb:Query',
'dynamodb:Scan',
'dynamodb:UpdateItem',
'dynamodb:CreateTable',
'dynamodb:DeleteTable'
]
})
);
const cloudWatchEndpoint = new ec2.InterfaceVpcEndpoint(this, 'CloudWatchEndpoint', {
vpc: this.vpc,
service: ec2.InterfaceVpcEndpointAwsService.CLOUDWATCH_MONITORING,
open: false,
securityGroups: [this.vpcEndpointSecurityGroup]
});
cloudWatchEndpoint.addToPolicy(
new iam.PolicyStatement({
principals: [new iam.AnyPrincipal()], // NOSONAR - policy is on vpc endpoint, user principal is not known - typescript:S6270
actions: ['cloudwatch:PutMetricData'],
effect: iam.Effect.ALLOW,
resources: ['*'],
conditions: {
'StringEquals': {
'cloudwatch:namespace': ['AWS/ApiGateway', 'AWS/Kendra', 'AWS/Cognito', 'Langchain/LLM']
}
}
})
);
const cloudWatchLogsEndpoint = new ec2.InterfaceVpcEndpoint(this, 'CloudWatchLogsEndpoint', {
vpc: this.vpc,
service: ec2.InterfaceVpcEndpointAwsService.CLOUDWATCH_LOGS,
open: false,
securityGroups: [this.vpcEndpointSecurityGroup]
});
cloudWatchLogsEndpoint.addToPolicy(
new iam.PolicyStatement({
principals: [new iam.AnyPrincipal()], // NOSONAR - policy is on vpc endpoint, user principal is not known - typescript:S6270
actions: [
'logs:CreateLogGroup',
'logs:CreateLogStream',
'logs:PutLogEvents',
'logs:DescribeLogGroups',
'logs:DescribeLogStreams',
'logs:FilterLogEvents',
'logs:GetLogEvents',
'logs:PutLogEvents',
'logs:ListTagsForResource'
],
effect: iam.Effect.ALLOW,
resources: [`arn:${cdk.Aws.PARTITION}:logs:${cdk.Aws.REGION}:${cdk.Aws.ACCOUNT_ID}:log-group:*`] // NOSONAR - this is a wildcard.
})
);
const xrayEndpoint = new ec2.InterfaceVpcEndpoint(this, 'XRayEndpoint', {
vpc: this.vpc,
service: ec2.InterfaceVpcEndpointAwsService.XRAY,
open: false,
securityGroups: [this.vpcEndpointSecurityGroup]
});
xrayEndpoint.addToPolicy(
new iam.PolicyStatement({
principals: [new iam.AnyPrincipal()], // NOSONAR - policy is on vpc endpoint, user principal is not known - typescript:S6270
actions: ['xray:PutTraceSegments', 'xray:PutTelemetryRecords'],
effect: iam.Effect.ALLOW,
resources: ['*'] // NOSONAR - this is a wildcard since the desintation does not have an arn
})
);
const sqsEndpoint = new ec2.InterfaceVpcEndpoint(this, 'SQSEndpoint', {
vpc: this.vpc,
service: ec2.InterfaceVpcEndpointAwsService.SQS,
open: false,
securityGroups: [this.vpcEndpointSecurityGroup]
});
sqsEndpoint.addToPolicy(
new iam.PolicyStatement({
principals: [new iam.AnyPrincipal()], // NOSONAR - policy is on vpc endpoint, user principal is not known - typescript:S6270
actions: [
'sqs:sendMessage',
'sqs:ChangeMessageVisibility',
'sqs:DeleteMessage',
'sqs:GetQueueUrl',
'sqs:GetQueueAttributes',
'sqs:ReceiveMessage'
],
resources: ['*'],
effect: iam.Effect.ALLOW
})
);
} | /**
* Creates VPC endpoints for various AWS services within the VPC.
*
* This method sets up the following VPC endpoints:
*
* 1. DynamoDB Gateway Endpoint:
* - Allows resources within the VPC to access DynamoDB without going through the public internet.
* - Configured to be accessible from private subnets with egress.
* - Adds an IAM policy statement allowing various DynamoDB actions on all tables in the account.
*
* 2. CloudWatch Monitoring Interface Endpoint:
* - Allows resources within the VPC to send custom metrics to CloudWatch.
* - Configured to be accessible only from the specified security group.
* - Adds an IAM policy statement allowing the `PutMetricData` action on CloudWatch for specific namespaces.
*
* 3. CloudWatch Logs Interface Endpoint:
* - Allows resources within the VPC to send log data to CloudWatch Logs.
* - Configured to be accessible only from the specified security group.
* - Adds an IAM policy statement allowing various CloudWatch Logs actions on all log groups in the account.
*
* 4. AWS X-Ray Interface Endpoint:
* - Allows resources within the VPC to send trace data to X-Ray.
* - Configured to be accessible only from the specified security group.
* - Adds an IAM policy statement allowing the `PutTraceSegments` and `PutTelemetryRecords` actions on X-Ray.
*
* 5. Amazon SQS Interface Endpoint:
* - Allows resources within the VPC to interact with SQS queues.
* - Configured to be accessible only from the specified security group.
* - Adds an IAM policy statement allowing various SQS actions on all queues.
*
* The purpose of this method is to create secure connections between resources within the VPC
* and various AWS services, without exposing them to the public internet. By using VPC endpoints,
* traffic between the VPC and the services is routed through the Amazon network, providing enhanced
* security and reducing data transfer costs.
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/vpc/custom-vpc.ts#L120-L233 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | CustomVPC.createVpc | protected createVpc(subnetCidrMask: number) {
const vpcFlowLogLogGroup = new logs.LogGroup(this, 'VPCFlowLogs', {
retention: LOG_RETENTION_PERIOD
});
const subnets: ec2.SubnetConfiguration[] = [
{
subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS,
name: 'private-egress',
cidrMask: subnetCidrMask
},
{
subnetType: ec2.SubnetType.PUBLIC,
name: 'public',
cidrMask: subnetCidrMask
}
];
const iPamPoolIdNotEmptyCondition = new cdk.CfnCondition(this, 'IPAMPoolIdProvidedCondition', {
expression: cdk.Fn.conditionNot(cdk.Fn.conditionEquals(this.iPamPoolId, ''))
});
const compatibleAzs = this.getCompatibleAzs();
this.vpc = new ec2.Vpc(this, 'UseCaseVPC', {
...(compatibleAzs && { availabilityZones: compatibleAzs }),
createInternetGateway: true,
subnetConfiguration: subnets,
flowLogs: {
flowLogs: {
destination: ec2.FlowLogDestination.toCloudWatchLogs(vpcFlowLogLogGroup),
trafficType: ec2.FlowLogTrafficType.REJECT
}
},
restrictDefaultSecurityGroup: true
});
const restrictDefaultSecurityGroupFunction: lambda.CfnFunction = this.node
.tryFindChild('Custom::VpcRestrictDefaultSGCustomResourceProvider')
?.node.tryFindChild('Handler') as lambda.CfnFunction;
createCustomResourceForLambdaLogRetention(
this,
'RestrictDefaultSecGrpFuncLogRetention',
restrictDefaultSecurityGroupFunction.ref,
this.customResourceLambdaArn
);
const cfnVpc: ec2.CfnVPC = this.vpc.node.defaultChild as ec2.CfnVPC;
cfnVpc.addPropertyOverride(
'CidrBlock',
// prettier-ignore
cdk.Fn.conditionIf(iPamPoolIdNotEmptyCondition.logicalId, cdk.Aws.NO_VALUE, `10.0.0.0/${subnetCidrMask - 4}`) // NOSONAR - have to provide CIDR if not available through IPAM
);
cfnVpc.addPropertyOverride(
'Ipv4IpamPoolId',
cdk.Fn.conditionIf(iPamPoolIdNotEmptyCondition.logicalId, this.iPamPoolId, cdk.Aws.NO_VALUE)
);
cfnVpc.addPropertyOverride(
'Ipv4NetmaskLength',
cdk.Fn.conditionIf(iPamPoolIdNotEmptyCondition.logicalId, 20, cdk.Aws.NO_VALUE)
);
const allSubnets = this.vpc
.selectSubnets({ subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS })
.subnets.concat(this.vpc.selectSubnets({ subnetType: ec2.SubnetType.PUBLIC }).subnets);
allSubnets.forEach((subnet, index) => {
const cfnSubnet = subnet.node.defaultChild as ec2.CfnSubnet;
cfnSubnet.addPropertyOverride(
'CidrBlock',
cdk.Fn.select(index, cdk.Fn.cidr(this.vpc.vpcCidrBlock, 6, (32 - subnetCidrMask).toString()))
);
});
cfn_nag.addCfnSuppressRules(
this.node
.tryFindChild('Custom::VpcRestrictDefaultSGCustomResourceProvider')
?.node.tryFindChild('Role') as cdk.CfnResource,
[
{
id: 'F10',
reason: 'Inline policy generated by CDK. The lambda role is associated with a function that suppresses default security group'
}
]
);
cfn_nag.addCfnSuppressRules(
this.node
.tryFindChild('Custom::VpcRestrictDefaultSGCustomResourceProvider')
?.node.tryFindChild('Handler') as cdk.CfnResource,
[
{
id: 'W89',
reason: 'VPC is not enforced, its an option to configure for the solution. This lambda does not have any business logic, it only removes default security group'
},
{
id: 'W92',
reason: 'The solution does not set reserved concurrency for lambda functions'
}
]
);
cfn_nag.addCfnSuppressRules(
this.vpc.node.tryFindChild('publicSubnet2')?.node.tryFindChild('Subnet') as ec2.Subnet,
[
{
id: 'W33',
reason: 'Subnet is a public subnet to host NAT gateways'
}
]
);
cfn_nag.addCfnSuppressRules(
this.vpc.node.tryFindChild('publicSubnet1')?.node.tryFindChild('Subnet') as ec2.Subnet,
[
{
id: 'W33',
reason: 'Subnet is a public subnet to host NAT gateways'
}
]
);
cfn_nag.addCfnSuppressRules(vpcFlowLogLogGroup, [
{
id: 'W84',
reason: 'Log group is encrypted by default with KMS'
}
]);
} | /**
* Create the VPC. Can be overridden by child classes for custom behaviour.
*
* @param subnetCidrMask
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/vpc/custom-vpc.ts#L369-L496 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | DeploymentPlatformVPC.getStackType | public getStackType(): string {
return 'deployment-platform';
} | /**
* Returns the stack type that the VPC is being used in. This could be use-case, deployment
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/vpc/deployment-platform-vpc.ts#L69-L71 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | SagemakerUseCaseVPC.getStackType | public getStackType(): string {
return 'sagemaker-use-case';
} | /**
* Returns the stack type that the VPC is being used in. This could be use-case, deployment
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/vpc/sagemaker-vpc.ts#L54-L56 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | TextUseCaseVPC.getStackType | public getStackType(): string {
throw new Error('Child classes should implement this method. This class should not be instantiated');
} | /**
* Returns the stack type that the VPC is being used in. This could be use-case, deployment
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/infrastructure/lib/vpc/text-use-case-vpc.ts#L175-L177 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | PermanentlyDeleteUseCaseCommand.constructor | constructor() { // NOSONAR - typescript:S4144 - this hierarchy is separate from line 49.
this.stackMgmt = new StackManagement();
this.storageMgmt = new StorageManagement();
this.useCaseConfigMgmt = new UseCaseConfigManagement();
} | // prettier-ignore | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/lambda/use-case-management/command.ts#L175-L179 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | ListUseCasesCommand.constructor | constructor() { // NOSONAR - typescript:S4144 - this hierarchy is separate from line 152.
this.stackMgmt = new StackManagement();
this.storageMgmt = new StorageManagement();
this.useCaseConfigMgmt = new UseCaseConfigManagement();
} | // prettier-ignore | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/lambda/use-case-management/command.ts#L288-L292 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | ListUseCasesCommand.filterUseCases | private filterUseCases(useCaseRecords: UseCaseRecord[], searchFilter: string) {
// Filter use cases based on search filter
const searchFilterLower = searchFilter.toLowerCase();
useCaseRecords = useCaseRecords.filter(
(useCaseRecord) =>
useCaseRecord.UseCaseId.toLowerCase().includes(searchFilterLower) ||
useCaseRecord.Name.toLowerCase().includes(searchFilterLower)
);
return useCaseRecords;
} | /**
* Filters use cases based on presence of the search filter in the UseCaseId and Name fields if present (case insensitive)
*
* @param useCaseRecords - Retrieved use case records from DDB to be filtered and selected from.
* @param searchFilter - Search filter provided by the user. Will search against UseCaseId and Name fields
* @returns - Filtered list of use cases to return to the user, and total number of
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/lambda/use-case-management/command.ts#L365-L375 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | ListUseCasesCommand.findNextPage | private findNextPage(
totalUseCases: number,
currentPage: number,
useCasesPerPage: number = DEFAULT_USE_CASES_PER_PAGE
) {
if (currentPage * useCasesPerPage < totalUseCases) {
return currentPage + 1;
}
return undefined;
} | /**
* Computes the next page number if there are more use cases beyond the current page.
*
* @param totalUseCases
* @param currentPage
* @param useCasesPerPage
* @returns the next page or undefined if there are no more use cases beyond the current page.
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/lambda/use-case-management/command.ts#L385-L394 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | ListUseCasesCommand.sortUseCasesByCreationDate | private sortUseCasesByCreationDate(useCaseRecords: UseCaseRecord[]) {
useCaseRecords.sort((a, b) => b.CreatedDate.localeCompare(a.CreatedDate));
return useCaseRecords;
} | /**
* sorts the use case records by creation date. This can be done lexicographically since dates are in ISO 8601 format,
* with the latest being shown first.
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/lambda/use-case-management/command.ts#L400-L403 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | ListUseCasesCommand.formatUseCasesToList | private formatUseCasesToList = (
useCaseDeploymentsMap: Map<string, DeploymentDetails>,
numUseCases: number,
nextPage: number | undefined
): any => {
// note: future server side sorting may go here
const formattedData: any = [];
try {
useCaseDeploymentsMap.forEach((value, key) => {
formattedData.push({
...value.useCaseRecord,
...value.useCaseDeploymentDetails,
...value.useCaseConfigDetails
});
});
const response = {
deployments: formattedData,
numUseCases: numUseCases,
nextPage: nextPage
};
logger.debug(`Formatted use cases list: ${JSON.stringify(response)}`);
return response;
} catch (error) {
logger.error('Deployments data formatting error. Likely use case config JSON parsing error');
throw error;
}
} | /**
* Formatting the data from ddb, use case config config, and a stack's deployment details to a list of use cases
* to send to the front end.
*
* @param useCaseDeploymentsMap
* @returns
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/lambda/use-case-management/command.ts | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | StackManagement.createStackInfoFromDdbRecord | private static parseStackDetails = (stackDetails: Stack): UseCaseStackDetails => {
const findParameterValue = (key: string): string | undefined => {
return stackDetails.Parameters?.find((param) => param.ParameterKey === key)?.ParameterValue;
};
const findOutputValue = (key: string): string | undefined => {
return stackDetails.Outputs?.find((param) => param.OutputKey === key)?.OutputValue;
};
const findListOutputValue = (key: string): string[] | undefined => {
return findOutputValue(key)?.split(',');
};
return {
status: stackDetails.StackStatus,
defaultUserEmail: findParameterValue(CfnParameterKeys.DefaultUserEmail),
useCaseUUID: findParameterValue(CfnParameterKeys.UseCaseUUID),
ragEnabled: findParameterValue(CfnParameterKeys.RAGEnabled),
deployUI: findParameterValue(CfnParameterKeys.DeployUI),
webConfigKey: findOutputValue(CfnOutputKeys.WebConfigKey),
knowledgeBaseType: findParameterValue(CfnParameterKeys.KnowledgeBaseType),
kendraIndexId: findOutputValue(CfnOutputKeys.KendraIndexId),
bedrockKnowledgeBaseId: findParameterValue(CfnParameterKeys.BedrockKnowledgeBaseId),
cloudFrontWebUrl: findOutputValue(CfnOutputKeys.CloudFrontWebUrl),
cloudwatchDashboardUrl: findOutputValue(CfnOutputKeys.CloudwatchDashboardUrl),
vpcEnabled: findParameterValue(CfnParameterKeys.VpcEnabled),
createNewVpc: findParameterValue(CfnParameterKeys.CreateNewVpc),
vpcId: findOutputValue(CfnOutputKeys.VpcId),
privateSubnetIds: findListOutputValue(CfnOutputKeys.PrivateSubnetIds),
securityGroupIds: findListOutputValue(CfnOutputKeys.SecurityGroupIds)
};
} | /**
* Parse the stack details to get a subset of the required details
* @param stackDetails response of describe stack for a single stack
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/lambda/use-case-management/cfn/stack-management.ts | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | parameters | const parameters = (cfnParameters: Map<string, string>): Parameter[] => {
let parameterArray: Parameter[] = new Array();
cfnParameters.forEach((value, key) => {
parameterArray.push({
ParameterKey: key,
ParameterValue: value
});
});
return parameterArray;
}; | /**
* utility method to build the Parameter array from the Map
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/lambda/use-case-management/cfn/stack-operation-builder.ts#L135-L145 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | updateParameters | const updateParameters = (cfnParameters: Map<string, string>): Parameter[] => {
let parameterArray: Parameter[] = parameters(cfnParameters);
for (let parameter of RetainedCfnParameterKeys) {
if (!cfnParameters.has(parameter)) {
parameterArray.push({
ParameterKey: parameter,
UsePreviousValue: true
});
}
}
return parameterArray;
}; | /**
* Utility method to build the Parameter array from the Map on updates, marking parameters to be retained
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/lambda/use-case-management/cfn/stack-operation-builder.ts#L150-L161 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | getTemplateUrl | const getTemplateUrl = (useCase: UseCase): string => {
if (process.env[ARTIFACT_KEY_PREFIX_ENV_VAR]) {
return `https://${process.env[ARTIFACT_BUCKET_ENV_VAR]}.s3.amazonaws.com/${process.env[ARTIFACT_KEY_PREFIX_ENV_VAR]}/${useCase.templateName}${process.env[TEMPLATE_FILE_EXTN_ENV_VAR]}`;
} else {
return `https://${process.env[ARTIFACT_BUCKET_ENV_VAR]}.s3.amazonaws.com/${useCase.templateName}${process.env[TEMPLATE_FILE_EXTN_ENV_VAR]}`;
}
}; | /**
* Utility method to get template URL using the useCase object that is passed to it
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/lambda/use-case-management/cfn/stack-operation-builder.ts#L166-L172 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | TextUseCaseValidator.resolveBedrockModelSourceOnUpdate | public static resolveBedrockModelSourceOnUpdate(updateConfig: any, mergedConfig: any): any {
let resolvedConfig = mergedConfig;
// only perform this action if our merged config is invalid (has both a ModelId and an InferenceProfileId)
if (
mergedConfig.LlmParams?.BedrockLlmParams?.ModelId &&
mergedConfig.LlmParams?.BedrockLlmParams?.InferenceProfileId
) {
// switching rom an inference profile to a model
if (updateConfig.LlmParams?.BedrockLlmParams?.ModelId) {
resolvedConfig.LlmParams.BedrockLlmParams.ModelId = updateConfig.LlmParams.BedrockLlmParams.ModelId;
delete resolvedConfig.LlmParams.BedrockLlmParams.InferenceProfileId;
}
// switching from a model to an inference profile
else if (updateConfig.LlmParams?.BedrockLlmParams?.InferenceProfileId) {
resolvedConfig.LlmParams.BedrockLlmParams.InferenceProfileId =
updateConfig.LlmParams.BedrockLlmParams.InferenceProfileId;
delete resolvedConfig.LlmParams.BedrockLlmParams.ModelId;
// if previously using a provisioned model, ModelArn would be present and should be removed
if (resolvedConfig.LlmParams?.BedrockLlmParams?.ModelArn) {
delete resolvedConfig.LlmParams?.BedrockLlmParams?.ModelArn;
}
}
}
return resolvedConfig;
} | /**
* Function to be applied to an updated use case configuration which will restrict the BedrockLlmParams to only contain one of the InferenceProfileId or ModelId. Required since merging of new and existing configs on updates will retain both values.
*
* @param newConfig The new config object coming from an update request
* @param mergedConfig A merged config from existing and new configs
* @returns A resolved config which has only 1 of the InferenceProfileId or ModelId.
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/lambda/use-case-management/model/use-case-validator.ts#L198-L224 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | UseCase.constructor | constructor( //NOSONAR - typescript:S107 - data model class hence needs primitive types as parameters
useCaseId: string,
name: string,
description: string | undefined,
cfnParameters: Map<string, string> | undefined,
configuration: UseCaseConfiguration,
userId: string,
providerName: string,
useCaseType: string,
) {
this.useCaseId = useCaseId;
this.name = name;
this.description = description;
this.cfnParameters = cfnParameters;
this.configuration = configuration;
this.userId = userId;
this.providerName = providerName
this.shortUUID = this.useCaseId.substring(0, 8);
this.templateName = `${providerName}${useCaseType}`;
this.useCaseType = useCaseType;
} | // prettier-ignore | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/lambda/use-case-management/model/use-case.ts#L72-L92 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | UseCase.clone | public clone(): UseCase {
let newUseCase = new UseCase(
this.useCaseId,
this.name,
this.description,
new Map<string, string>(this.cfnParameters),
{ ...this.configuration },
this.userId,
this.templateName
.split(/(?=[A-Z])/)
.slice(0, -1)
.join(''), // provider name
this.templateName.split(/(?=[A-Z])/).pop()! // use case type, the last capitalized portion
);
return newUseCase;
} | /**
* Performs a deep copy of this object, preserving methods and property values
*
* @returns a deep copy of the object
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/lambda/use-case-management/model/use-case.ts#L130-L146 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | UseCase.setParameterIfExists | protected static setParameterIfExists(
cfnParameters: Map<string, string>,
paramName: string,
value: any | undefined
): void {
if (value !== undefined) {
cfnParameters.set(paramName, value.toString());
}
} | /**
* If the provided value is defined, sets the correct Cloudformation Parameter to that value as a string.
*
* @param cfnParameters The parameter map to set the value in
* @param paramName Name of the Cloudformation Parameter to set
* @param value value to set
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/lambda/use-case-management/model/use-case.ts#L155-L163 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | UseCase.setBooleanParameterIfExists | protected static setBooleanParameterIfExists(
cfnParameters: Map<string, string>,
paramName: string,
value: boolean | undefined
): void {
if (value !== undefined) {
if (value) {
cfnParameters.set(paramName, 'Yes');
} else {
cfnParameters.set(paramName, 'No');
}
}
} | /**
* If the provided value is defined, sets the correct Cloudformation Parameter to 'Yes' or 'No' accordingly.
*
* @param cfnParameters The parameter map to set the value in
* @param paramName Name of the Cloudformation Parameter to set
* @param value boolean value to set
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/lambda/use-case-management/model/use-case.ts#L172-L184 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | UseCase.setListParameterIfExists | protected static setListParameterIfExists(
cfnParameters: Map<string, string>,
paramName: string,
values: Array<any> | undefined
): void {
if (values !== undefined) {
let valueString = '';
for (const item of values) {
valueString += item.toString() + ',';
}
// remove trailing comma
if (valueString.charAt(valueString.length - 1) == ',') {
valueString = valueString.slice(0, -1);
}
cfnParameters.set(paramName, valueString);
}
} | /**
* If the provided value is defined, sets the correct Cloudformation Parameter to a comma separated list of the values.
*
* @param cfnParameters The parameter map to set the value in
* @param paramName Name of the Cloudformation Parameter to set
* @param values Array of values to set
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/lambda/use-case-management/model/use-case.ts#L193-L209 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | deployUseCasePostRequest | const deployUseCasePostRequest = async (endpoint: string, params = {}) => {
setUseCaseDeployStatus(DEPLOYMENT_STATUS_NOTIFICATION.PENDING);
const token = await generateToken();
const response = await API.post(API_NAME, endpoint, {
body: params,
headers: {
Authorization: token
}
});
setUseCaseDeployStatus(DEPLOYMENT_STATUS_NOTIFICATION.SUCCESS);
return response;
}; | /**
* Make a reqeust to deploy a use case using CloudFormation
* POST /deployments/
*
* @param {string} endpoint API Endpoint to call
* @param {Object} params Use case deployment params to send to the API
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/ui-deployment/src/components/wizard/WizardView.tsx#L140-L151 | b278845810db549e19740c5a2405faee959b82a3 |
generative-ai-application-builder-on-aws | github_2023 | aws-solutions | typescript | getRequiredFields | const getRequiredFields = (modelName: string, provisionedModel: boolean): string[] => {
if (modelName === INFERENCE_PROFILE) {
return ['modelName', 'inferenceProfileId'];
}
if (provisionedModel) {
return ['modelName', 'modelArn'];
}
return ['modelName'];
}; | /**
*
* @param modelProvider Value of model provider selected in the dropdown
* @param provisionedModel Whether the model is provisioned or not
*/ | https://github.com/aws-solutions/generative-ai-application-builder-on-aws/blob/b278845810db549e19740c5a2405faee959b82a3/source/ui-deployment/src/components/wizard/Model/helpers.ts#L190-L198 | b278845810db549e19740c5a2405faee959b82a3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.