Skip to content

Commit

Permalink
chore(format): reformat via prettify
Browse files Browse the repository at this point in the history
  • Loading branch information
massi-ang authored and dairiley committed Jan 23, 2024
1 parent eca9a50 commit 4a1e4ac
Show file tree
Hide file tree
Showing 27 changed files with 400 additions and 248 deletions.
4 changes: 2 additions & 2 deletions bin/aws-genai-llm-chatbot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import * as cdk from "aws-cdk-lib";
import "source-map-support/register";
import { AwsGenAILLMChatbotStack } from "../lib/aws-genai-llm-chatbot-stack";
import { AwsSolutionsChecks } from "cdk-nag"
import { AwsSolutionsChecks } from "cdk-nag";
import { getConfig } from "./config";
import { Aspects } from "aws-cdk-lib";

Expand All @@ -18,4 +18,4 @@ new AwsGenAILLMChatbotStack(app, `${config.prefix}GenAIChatBotStack`, {
},
});

Aspects.of(app).add(new AwsSolutionsChecks({verbose: true}));
Aspects.of(app).add(new AwsSolutionsChecks({ verbose: true }));
11 changes: 4 additions & 7 deletions cli/magic-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,7 @@ async function processCreateOptions(options: any): Promise<void> {
type: "confirm",
name: "kendraEnterprise",
message: "Do you want to enable Kendra Enterprise Edition?",
initial:
options.kendraEnterprise ||
false,
initial: options.kendraEnterprise || false,
skip(): boolean {
return !(this as any).state.answers.ragsToEnable.includes("kendra");
},
Expand Down Expand Up @@ -336,7 +334,7 @@ async function processCreateOptions(options: any): Promise<void> {
enabled: false,
createIndex: false,
external: [{}],
enterprise: false
enterprise: false,
},
},
embeddingsModels: [{}],
Expand Down Expand Up @@ -366,8 +364,7 @@ async function processCreateOptions(options: any): Promise<void> {
config.rag.engines.kendra.enabled =
config.rag.engines.kendra.createIndex || kendraExternal.length > 0;
config.rag.engines.kendra.external = [...kendraExternal];
config.rag.engines.kendra.enterprise =
answers.kendraEnterprise
config.rag.engines.kendra.enterprise = answers.kendraEnterprise;

console.log("\n✨ This is the chosen configuration:\n");
console.log(JSON.stringify(config, undefined, 2));
Expand All @@ -383,4 +380,4 @@ async function processCreateOptions(options: any): Promise<void> {
).create
? createConfig(config)
: console.log("Skipping");
}
}
14 changes: 8 additions & 6 deletions lib/authentication/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,13 @@ export class Authentication extends Construct {
/**
* CDK NAG suppression
*/
NagSuppressions.addResourceSuppressions(userPool,
[
{id: "AwsSolutions-COG1", reason: "Default password policy requires min length of 8, digits, lowercase characters, symbols and uppercase characters: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_cognito.PasswordPolicy.html"},
{id: "AwsSolutions-COG2", reason: "MFA not required for user usage."}
]
);
NagSuppressions.addResourceSuppressions(userPool, [
{
id: "AwsSolutions-COG1",
reason:
"Default password policy requires min length of 8, digits, lowercase characters, symbols and uppercase characters: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_cognito.PasswordPolicy.html",
},
{ id: "AwsSolutions-COG2", reason: "MFA not required for user usage." },
]);
}
}
170 changes: 121 additions & 49 deletions lib/aws-genai-llm-chatbot-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,20 @@ export class AwsGenAILLMChatbotStack extends cdk.Stack {
/**
* CDK NAG suppression
*/
NagSuppressions.addResourceSuppressionsByPath(this,
NagSuppressions.addResourceSuppressionsByPath(
this,
[
`/${this.stackName}/Custom::CDKBucketDeployment8693BB64968944B69AAFB0CC9EB8756C/Resource`
`/${this.stackName}/Custom::CDKBucketDeployment8693BB64968944B69AAFB0CC9EB8756C/Resource`,
],
[
{id: "AwsSolutions-L1", reason: "Lambda function created implicitly by CDK."},
{
id: "AwsSolutions-L1",
reason: "Lambda function created implicitly by CDK.",
},
]
);
NagSuppressions.addResourceSuppressionsByPath(this,
NagSuppressions.addResourceSuppressionsByPath(
this,
[
`/${this.stackName}/Authentication/IdentityPool/AuthenticatedRole/DefaultPolicy/Resource`,
`/${this.stackName}/Authentication/UserPool/smsRole/Resource`,
Expand All @@ -184,47 +189,66 @@ export class AwsGenAILLMChatbotStack extends cdk.Stack {
`/${this.stackName}/ChatBotApi/RestApi/GraphQLApiHandler/ServiceRole/DefaultPolicy/Resource`,
`/${this.stackName}/ChatBotApi/Realtime/Resolvers/lambda-resolver/ServiceRole/Resource`,
`/${this.stackName}/ChatBotApi/Realtime/Resolvers/outgoing-message-handler/ServiceRole/Resource`,
`/${this.stackName}/ChatBotApi/Realtime/Resolvers/outgoing-message-handler/ServiceRole/DefaultPolicy/Resource`
`/${this.stackName}/ChatBotApi/Realtime/Resolvers/outgoing-message-handler/ServiceRole/DefaultPolicy/Resource`,
],
[
{id: "AwsSolutions-IAM4", reason: "IAM role implicitly created by CDK."},
{id: "AwsSolutions-IAM5", reason: "IAM role implicitly created by CDK."},
{
id: "AwsSolutions-IAM4",
reason: "IAM role implicitly created by CDK.",
},
{
id: "AwsSolutions-IAM5",
reason: "IAM role implicitly created by CDK.",
},
]
);

if (ideficsModels.length > 0) {
NagSuppressions.addResourceSuppressionsByPath(this,
NagSuppressions.addResourceSuppressionsByPath(
this,
[
`/${this.stackName}/IdeficsInterface/IdeficsInterfaceRequestHandler/ServiceRole/DefaultPolicy/Resource`,
`/${this.stackName}/IdeficsInterface/IdeficsInterfaceRequestHandler/ServiceRole/Resource`,
`/${this.stackName}/IdeficsInterface/S3IntegrationRole/DefaultPolicy/Resource`
`/${this.stackName}/IdeficsInterface/S3IntegrationRole/DefaultPolicy/Resource`,
],
[
{id: "AwsSolutions-IAM4", reason: "IAM role implicitly created by CDK."},
{id: "AwsSolutions-IAM5", reason: "IAM role implicitly created by CDK."},
{
id: "AwsSolutions-IAM4",
reason: "IAM role implicitly created by CDK.",
},
{
id: "AwsSolutions-IAM5",
reason: "IAM role implicitly created by CDK.",
},
]
);
NagSuppressions.addResourceSuppressionsByPath(this,
NagSuppressions.addResourceSuppressionsByPath(
this,
`/${this.stackName}/IdeficsInterface/ChatbotFilesPrivateApi/DeploymentStage.prod/Resource`,
[
{id: "AwsSolutions-APIG3", reason: "WAF not required due to configured Cognito auth."}
{
id: "AwsSolutions-APIG3",
reason: "WAF not required due to configured Cognito auth.",
},
]
);
NagSuppressions.addResourceSuppressionsByPath(this,
NagSuppressions.addResourceSuppressionsByPath(
this,
[
`/${this.stackName}/IdeficsInterface/ChatbotFilesPrivateApi/Default/{object}/ANY/Resource`,
`/${this.stackName}/IdeficsInterface/ChatbotFilesPrivateApi/Default/{object}/ANY/Resource`
`/${this.stackName}/IdeficsInterface/ChatbotFilesPrivateApi/Default/{object}/ANY/Resource`,
],
[
{id: "AwsSolutions-APIG4", reason: "Private API within a VPC."},
{id: "AwsSolutions-COG4", reason: "Private API within a VPC."}
{ id: "AwsSolutions-APIG4", reason: "Private API within a VPC." },
{ id: "AwsSolutions-COG4", reason: "Private API within a VPC." },
]
);
}

// RAG configuration
if (props.config.rag.enabled) {
NagSuppressions.addResourceSuppressionsByPath(this,
NagSuppressions.addResourceSuppressionsByPath(
this,
[
`/${this.stackName}/RagEngines/DataImport/FileImportBatchJob/FileImportJobRole/DefaultPolicy/Resource`,
`/${this.stackName}/RagEngines/DataImport/FileImportBatchJob/FileImportContainer/ExecutionRole/DefaultPolicy/Resource`,
Expand All @@ -245,16 +269,26 @@ export class AwsGenAILLMChatbotStack extends cdk.Stack {
`/${this.stackName}/RagEngines/DataImport/RssSubscription/triggerRssIngestorsFunction/ServiceRole/Resource`,
`/${this.stackName}/RagEngines/DataImport/RssSubscription/triggerRssIngestorsFunction/ServiceRole/DefaultPolicy/Resource`,
`/${this.stackName}/RagEngines/DataImport/RssSubscription/crawlQueuedRssPostsFunction/ServiceRole/Resource`,
`/${this.stackName}/RagEngines/DataImport/RssSubscription/crawlQueuedRssPostsFunction/ServiceRole/DefaultPolicy/Resource`
`/${this.stackName}/RagEngines/DataImport/RssSubscription/crawlQueuedRssPostsFunction/ServiceRole/DefaultPolicy/Resource`,
],
[
{id: "AwsSolutions-IAM4", reason: "IAM role implicitly created by CDK."},
{id: "AwsSolutions-IAM5", reason: "IAM role implicitly created by CDK."},
{
id: "AwsSolutions-IAM4",
reason: "IAM role implicitly created by CDK.",
},
{
id: "AwsSolutions-IAM5",
reason: "IAM role implicitly created by CDK.",
},
]
);

if (props.config.rag.engines.aurora.enabled || props.config.rag.engines.opensearch.enabled) {
NagSuppressions.addResourceSuppressionsByPath(this,
if (
props.config.rag.engines.aurora.enabled ||
props.config.rag.engines.opensearch.enabled
) {
NagSuppressions.addResourceSuppressionsByPath(
this,
[
`/${this.stackName}/RagEngines/SageMaker/Model/MultiAB24A/CodeBuildRole/DefaultPolicy/Resource`,
`/${this.stackName}/RagEngines/SageMaker/Model/MultiAB24A/OnEventHandler/ServiceRole/Resource`,
Expand All @@ -269,18 +303,29 @@ export class AwsGenAILLMChatbotStack extends cdk.Stack {
`/${this.stackName}/RagEngines/SageMaker/Model/MultiAB24A/SageMakerExecutionRole/DefaultPolicy/Resource`,
],
[
{id: "AwsSolutions-IAM4", reason: "IAM role implicitly created by CDK."},
{id: "AwsSolutions-IAM5", reason: "IAM role implicitly created by CDK."},
{
id: "AwsSolutions-IAM4",
reason: "IAM role implicitly created by CDK.",
},
{
id: "AwsSolutions-IAM5",
reason: "IAM role implicitly created by CDK.",
},
]
);
if (props.config.rag.engines.aurora.enabled) {
NagSuppressions.addResourceSuppressionsByPath(this,
NagSuppressions.addResourceSuppressionsByPath(
this,
`/${this.stackName}/RagEngines/AuroraPgVector/AuroraDatabase/Secret/Resource`,
[
{id: "AwsSolutions-SMG4", reason: "Secret created implicitly by CDK."}
{
id: "AwsSolutions-SMG4",
reason: "Secret created implicitly by CDK.",
},
]
);
NagSuppressions.addResourceSuppressionsByPath(this,
NagSuppressions.addResourceSuppressionsByPath(
this,
[
`/${this.stackName}/RagEngines/AuroraPgVector/DatabaseSetupFunction/ServiceRole/Resource`,
`/${this.stackName}/RagEngines/AuroraPgVector/DatabaseSetupProvider/framework-onEvent/ServiceRole/Resource`,
Expand All @@ -290,56 +335,83 @@ export class AwsGenAILLMChatbotStack extends cdk.Stack {
`/${this.stackName}/RagEngines/AuroraPgVector/CreateAuroraWorkspace/CreateAuroraWorkspace/Role/DefaultPolicy/Resource`,
],
[
{id: "AwsSolutions-IAM4", reason: "IAM role implicitly created by CDK."},
{id: "AwsSolutions-IAM5", reason: "IAM role implicitly created by CDK."},
{
id: "AwsSolutions-IAM4",
reason: "IAM role implicitly created by CDK.",
},
{
id: "AwsSolutions-IAM5",
reason: "IAM role implicitly created by CDK.",
},
]
);
}
if (props.config.rag.engines.opensearch.enabled) {
NagSuppressions.addResourceSuppressionsByPath(this,
NagSuppressions.addResourceSuppressionsByPath(
this,
[
`/${this.stackName}/RagEngines/OpenSearchVector/CreateOpenSearchWorkspace/CreateOpenSearchWorkspaceFunction/ServiceRole/Resource`,
`/${this.stackName}/RagEngines/OpenSearchVector/CreateOpenSearchWorkspace/CreateOpenSearchWorkspaceFunction/ServiceRole/DefaultPolicy/Resource`,
`/${this.stackName}/RagEngines/OpenSearchVector/CreateOpenSearchWorkspace/CreateOpenSearchWorkspace/Role/DefaultPolicy/Resource`,
],
[
{id: "AwsSolutions-IAM4", reason: "IAM role implicitly created by CDK."},
{id: "AwsSolutions-IAM5", reason: "IAM role implicitly created by CDK."},
{
id: "AwsSolutions-IAM4",
reason: "IAM role implicitly created by CDK.",
},
{
id: "AwsSolutions-IAM5",
reason: "IAM role implicitly created by CDK.",
},
]
);
}
}
if (props.config.rag.engines.kendra.enabled) {
NagSuppressions.addResourceSuppressionsByPath(this,
NagSuppressions.addResourceSuppressionsByPath(
this,
[
`/${this.stackName}/RagEngines/KendraRetrieval/CreateAuroraWorkspace/CreateKendraWorkspace/Role/DefaultPolicy/Resource`,
],
[
{id: "AwsSolutions-IAM4", reason: "IAM role implicitly created by CDK."},
{id: "AwsSolutions-IAM5", reason: "IAM role implicitly created by CDK."},
{
id: "AwsSolutions-IAM4",
reason: "IAM role implicitly created by CDK.",
},
{
id: "AwsSolutions-IAM5",
reason: "IAM role implicitly created by CDK.",
},
]
);
NagSuppressions.addResourceSuppressionsByPath(this,
NagSuppressions.addResourceSuppressionsByPath(
this,
[
`/${this.stackName}/RagEngines/KendraRetrieval/KendraRole/DefaultPolicy/Resource`
`/${this.stackName}/RagEngines/KendraRetrieval/KendraRole/DefaultPolicy/Resource`,
],
[
{id: "AwsSolutions-IAM5", reason: "Access to all log groups required for CloudWatch log group creation."},
{
id: "AwsSolutions-IAM5",
reason:
"Access to all log groups required for CloudWatch log group creation.",
},
]
);
}
}
// Implicitly created resources with changing paths
NagSuppressions.addStackSuppressions(this,
[
{id: "CdkNagValidationFailure", reason: "Intrinstic function references."},
]
);
NagSuppressions.addStackSuppressions(this, [
{
id: "CdkNagValidationFailure",
reason: "Intrinstic function references.",
},
]);
// Lambda functions still using Python 3.11 even though latest runtime is 3.12. Can be removed after upgrade.
NagSuppressions.addStackSuppressions(this,
[
{id: "AwsSolutions-L1", reason: "Not yet upgraded from Python 3.11 to 3.12."},
]
);
NagSuppressions.addStackSuppressions(this, [
{
id: "AwsSolutions-L1",
reason: "Not yet upgraded from Python 3.11 to 3.12.",
},
]);
}
}
2 changes: 1 addition & 1 deletion lib/chatbot-api/chatbot-dynamodb-tables/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class ChatBotDynamoDBTables extends Construct {
billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
encryption: dynamodb.TableEncryption.AWS_MANAGED,
removalPolicy: cdk.RemovalPolicy.DESTROY,
pointInTimeRecovery: true
pointInTimeRecovery: true,
});

sessionsTable.addGlobalSecondaryIndex({
Expand Down
13 changes: 7 additions & 6 deletions lib/chatbot-api/chatbot-s3-buckets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class ChatBotS3Buckets extends Construct {
autoDeleteObjects: true,
transferAcceleration: true,
enforceSSL: true,
serverAccessLogsBucket: logsBucket,
serverAccessLogsBucket: logsBucket,
cors: [
{
allowedHeaders: ["*"],
Expand All @@ -44,10 +44,11 @@ export class ChatBotS3Buckets extends Construct {
/**
* CDK NAG suppression
*/
NagSuppressions.addResourceSuppressions(logsBucket,
[
{id: "AwsSolutions-S1", reason: "Logging bucket does not require it's own access logs."},
]
);
NagSuppressions.addResourceSuppressions(logsBucket, [
{
id: "AwsSolutions-S1",
reason: "Logging bucket does not require it's own access logs.",
},
]);
}
}
Loading

0 comments on commit 4a1e4ac

Please sign in to comment.