Skip to content

Commit 5460b4e

Browse files
authored
feat(global): global updates (#25)
* add catalog of available constructs to README * use strongly types construct props * update os domain type
1 parent 5488709 commit 5460b4e

File tree

5 files changed

+60
-68
lines changed

5 files changed

+60
-68
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- [CDK Versions](#cdk-versions)
2020
- [Contributing](#contributing)
2121
- [Adding new constructs](#design-guidelines-and-development-guide)
22+
- [Catalog](#catalog)
2223
- [Sample Use Cases](#sample-use-cases)
2324
- [Roadmap](#roadmap)
2425

@@ -40,6 +41,17 @@ Contributions of all kinds are welcome! Check out our [contributor's guide](./CO
4041

4142
If you want to add a new construct to the library, check out our first our [design guidelines](./DESIGN_GUIDELINES.md), then follow the [development guide](./DEVELOPER_GUIDE.md)
4243

44+
# Catalog
45+
46+
The following constructs are available in the library:
47+
48+
| **Construct**| Emerging Tech Area |Description| AWS Services used |
49+
|:-------------|:-------------|:-------------|:-------------|
50+
| [Data ingestion pipeline](./src/patterns/gen-ai/aws-rag-appsync-stepfn-opensearch/) | Generative AI | Ingestion pipeline providing a RAG (Retrieval Augmented Generation) source for storing documents in a knowledge base. | Amazon Opensearch, AWS Step Functions, Amazon bedrock, AWS Appsync, AWS Lambda |
51+
| [Question answering](./src/patterns/gen-ai/aws-qa-appsync-opensearch/) | Generative AI | Question answering against a Large Language Model (Anthropic Claude V2) using a RAG (Retrieval Augmented Generation) source and/or long context window. | Amazon Opensearch, AWS Lambda, Amazon bedrock, AWS Appsync |
52+
| [Summarization](./src/patterns/gen-ai/aws-summarization-appsync-stepfn/) | Generative AI | Document summarization using a Large Language Model (Anthropic Claude V2). | AWS Lambda, Amazon bedrock, AWS Appsync, Amazon Elasticache for Redis |
53+
| [Lambda layer](./src/patterns/gen-ai/aws-langchain-common-layer/) | Generative AI | Python lambda layer providing dependencies and utilities to develop Generative AI applications on AWS. | AWS Lambda, Amazon bedrock, Amazon SageMaker |
54+
4355
# Sample Use Cases
4456

4557
This library includes a collection of functional use case implementations to demonstrate the usage of AWS Emerging Tech Constructs architectural patterns. These can be used in the same way as architectural patterns, and can be conceptualized as an additional "higher-level" abstraction of those patterns. Those patterns (constructs) are composed together into [stacks](https://docs.aws.amazon.com/cdk/latest/guide/stacks.html), forming a "CDK app".

src/patterns/gen-ai/aws-qa-appsync-opensearch/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ Parameters
5555

5656
| **Name** | **Type** | **Required** |**Description** |
5757
|:-------------|:----------------|-----------------|-----------------|
58-
| openSearchDomainEndpoint | string | ![Required](https://img.shields.io/badge/required-ff0000) | Domain endpoint for the OpenSearch Service. |
59-
| openSearchDomainName | string| ![Required](https://img.shields.io/badge/required-ff0000) | Domain name for the OpenSearch Service. |
58+
| existingOpenSearchDomain | [aws_opensearchservice.IDomain](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_opensearchservice.IDomain.html)| ![Required](https://img.shields.io/badge/required-ff0000) | Existing domain for the OpenSearch Service. |
59+
| openSearchSecret | [aws_secrets_manager.ISecret](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_secretsmanager.ISecret.html) | ![Required](https://img.shields.io/badge/required-ff0000) | Secret containing credentials to authenticate to the existing opensearch domain. |
6060
| openSearchIndexName | string | ![Required](https://img.shields.io/badge/required-ff0000) | Domain endpoint for the OpenSearch Service. |
6161
| cognitoUserPool | [cognito.IUserPool](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_cognito.IUserPool.html) | ![Required](https://img.shields.io/badge/required-ff0000) | Cognito user pool used for authentication. |
6262
| vpcProps | [ec2.VpcProps](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.VpcProps.html) | ![Optional](https://img.shields.io/badge/optional-4169E1) | Custom properties for a VPC the construct will create. This VPC will be used by the Lambda functions the construct creates. Providing both this and existingVpc is an error. |
@@ -66,8 +66,7 @@ Parameters
6666
| existingInputAssetsBucketObj | [s3.IBucket](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.IBucket.html) | ![Optional](https://img.shields.io/badge/optional-4169E1) | Existing instance of S3 Bucket object, providing both this and `bucketInputsAssetsProps` will cause an error. |
6767
| bucketInputsAssetsProps | [s3.BucketProps](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.BucketProps.html) | ![Optional](https://img.shields.io/badge/optional-4169E1) | User provided props to override the default props for the S3 Bucket. Providing both this and `existingInputAssetsBucketObj` will cause an error. |
6868
| stage | string | ![Optional](https://img.shields.io/badge/optional-4169E1) | Value will be appended to resources name Service. |
69-
| mergedApiGraphQLEndpoint | string | ![Optional](https://img.shields.io/badge/optional-4169E1) | URL endpoint of the appsync merged api |
70-
| mergedApiGraphQLId | string | ![Optional](https://img.shields.io/badge/optional-4169E1) | Api Id of the appsync merged api |
69+
| existingMergedApi | [appsync.CfnGraphQLApi](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_appsync.CfnGraphQLApi.html) | ![Optional](https://img.shields.io/badge/optional-4169E1) | Existing merged api instance. The merge API provode a federated schema over source API schemas.|
7170

7271
## Pattern Properties
7372

src/patterns/gen-ai/aws-qa-appsync-opensearch/index.ts

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ import * as targets from 'aws-cdk-lib/aws-events-targets';
2020
import * as iam from 'aws-cdk-lib/aws-iam';
2121
import * as lambda from 'aws-cdk-lib/aws-lambda';
2222
import * as logs from 'aws-cdk-lib/aws-logs';
23+
import * as opensearchservice from 'aws-cdk-lib/aws-opensearchservice';
2324
import * as s3 from 'aws-cdk-lib/aws-s3';
25+
import * as secret from 'aws-cdk-lib/aws-secretsmanager';
2426
import { Construct } from 'constructs';
2527
import * as s3_bucket_helper from '../../../common/helpers/s3-bucket-helper';
2628
import * as vpc_helper from '../../../common/helpers/vpc-helper';
@@ -71,41 +73,29 @@ export interface QaAppsyncOpensearchProps {
7173
*/
7274
readonly bucketInputsAssetsProps?: s3.BucketProps;
7375
/**
74-
* Domain name for the OpenSearch Service.
76+
* Existing Amazon OpenSearch Service domain.
7577
*
7678
* @default - None
7779
*/
78-
readonly openSearchDomainName: string;
80+
readonly existinOpensearchDomain: opensearchservice.IDomain;
7981
/**
80-
* Domain endpoint for the OpenSearch Service.
81-
*
82-
* @default - None
83-
*/
84-
readonly openSearchDomainEndpoint: string;
85-
/**
86-
* Index name for the OpenSearch Service.
82+
* Data Index name for the OpenSearch Service.
8783
*
8884
* @default - None
8985
*/
9086
readonly openSearchIndexName: string;
9187
/**
92-
* SecretsManager secret id to access the OpenSearch Service.
88+
* SecretsManager secret to authenticate against the OpenSearch Service domain.
9389
*
9490
* @default - None
9591
*/
96-
readonly openSearchSecretId: string;
92+
readonly openSearchSecret: secret.ISecret;
9793
/**
98-
* URL endpoint of the appsync merged api.
99-
*
100-
* @default - None
101-
*/
102-
readonly mergedApiGraphQLEndpoint?: string;
103-
/**
104-
* ApiId of the appsync merged api.
105-
*
106-
* @default - None
107-
*/
108-
readonly mergedApiGraphQLId?: string;
94+
* Existing merged Appsync GraphQL api.
95+
*
96+
* @default - None
97+
*/
98+
readonly existingMergedApi?: appsync.CfnGraphQLApi;
10999
/**
110100
* Cognito user pool used for authentication.
111101
*
@@ -256,8 +246,8 @@ export class QaAppsyncOpensearch extends Construct {
256246

257247
// If the user provides a mergedApi endpoint, the lambda
258248
// functions will use this endpoint to send their status updates
259-
const updateGraphQlApiEndpoint = !props.mergedApiGraphQLEndpoint ? question_answering_graphql_api.graphqlUrl : props.mergedApiGraphQLEndpoint;
260-
const updateGraphQlApiId = !props.mergedApiGraphQLId ? question_answering_graphql_api.apiId : props.mergedApiGraphQLId;
249+
const updateGraphQlApiEndpoint = !props.existingMergedApi ? question_answering_graphql_api.graphqlUrl : props.existingMergedApi.attrGraphQlUrl;
250+
const updateGraphQlApiId = !props.existingMergedApi ? question_answering_graphql_api.apiId : props.existingMergedApi.attrApiId;
261251

262252
const job_status_data_source = new appsync.NoneDataSource(
263253
this,
@@ -321,22 +311,25 @@ export class QaAppsyncOpensearch extends Construct {
321311
environment: {
322312
GRAPHQL_URL: updateGraphQlApiEndpoint,
323313
INPUT_BUCKET: this.s3InputAssetsBucketInterface.bucketName,
324-
OPENSEARCH_DOMAIN_ENDPOINT: props.openSearchDomainEndpoint,
314+
OPENSEARCH_DOMAIN_ENDPOINT: props.existinOpensearchDomain.domainEndpoint,
325315
OPENSEARCH_INDEX: props.openSearchIndexName,
326-
OPENSEARCH_SECRET_ID: props.openSearchSecretId,
316+
OPENSEARCH_SECRET_ID: props.openSearchSecret.secretName,
327317
},
328318
},
329319
);
330320

321+
// The lambda will access the opensearch credentials
322+
props.openSearchSecret.grantRead(question_answering_function);
323+
331324
// The lambda will pull processed files and create embeddings
332325
this.s3InputAssetsBucketInterface.grantRead(question_answering_function);
333326

334327
question_answering_function.addToRolePolicy(new iam.PolicyStatement({
335328
effect: iam.Effect.ALLOW,
336329
actions: ['es:*'],
337330
resources: [
338-
'arn:aws:es:'+Aws.REGION+':'+Aws.ACCOUNT_ID+':domain/'+props.openSearchDomainName+'/*',
339-
'arn:aws:es:'+Aws.REGION+':'+Aws.ACCOUNT_ID+':domain/'+props.openSearchDomainName,
331+
'arn:aws:es:'+Aws.REGION+':'+Aws.ACCOUNT_ID+':domain/'+props.existinOpensearchDomain.domainName+'/*',
332+
'arn:aws:es:'+Aws.REGION+':'+Aws.ACCOUNT_ID+':domain/'+props.existinOpensearchDomain.domainName,
340333
],
341334
}));
342335

src/patterns/gen-ai/aws-rag-appsync-stepfn-opensearch/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ Parameters
5151

5252
| **Name** | **Type** | **Required** |**Description** |
5353
|:-------------|:----------------|-----------------|-----------------|
54-
| openSearchDomainEndpoint | string | ![Required](https://img.shields.io/badge/required-ff0000) | Domain endpoint for the OpenSearch Service. |
55-
| openSearchDomainName | string| ![Required](https://img.shields.io/badge/required-ff0000) | Domain name for the OpenSearch Service. |
54+
| existingOpenSearchDomain | [aws_opensearchservice.IDomain](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_opensearchservice.IDomain.html)| ![Required](https://img.shields.io/badge/required-ff0000) | Existing domain for the OpenSearch Service. |
55+
| openSearchSecret | [aws_secrets_manager.ISecret](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_secretsmanager.ISecret.html) | ![Required](https://img.shields.io/badge/required-ff0000) | Secret containing credentials to authenticate to the existing opensearch domain. |
5656
| openSearchIndexName | string | ![Required](https://img.shields.io/badge/required-ff0000) | Domain endpoint for the OpenSearch Service. |
5757
| cognitoUserPool | [cognito.IUserPool](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_cognito.IUserPool.html) | ![Required](https://img.shields.io/badge/required-ff0000) | Cognito user pool used for authentication. |
5858
| vpcProps | [ec2.VpcProps](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.VpcProps.html) | ![Optional](https://img.shields.io/badge/optional-4169E1) | Custom properties for a VPC the construct will create. This VPC will be used by the Lambda functions the construct creates. Providing both this and existingVpc is an error. |
@@ -64,7 +64,7 @@ Parameters
6464
| existingProcessedAssetsBucketObj | [s3.IBucket](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.IBucket.html) | ![Optional](https://img.shields.io/badge/optional-4169E1) | Existing instance of S3 Bucket object, providing both this and `bucketProcessedAssetsProps` will cause an error. |
6565
| bucketProcessedAssetsProps | [s3.BucketProps](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.BucketProps.html) | ![Optional](https://img.shields.io/badge/optional-4169E1) | User provided props to override the default props for the S3 Bucket. Providing both this and `existingProcessedAssetsBucketObj` will cause an error. |
6666
| stage | string | ![Optional](https://img.shields.io/badge/optional-4169E1) | Value will be appended to resources name Service. |
67-
| mergedApiGraphQL | string | ![Optional](https://img.shields.io/badge/optional-4169E1) | URL endpoint of the appsync merged api |
67+
| existingMergedApi | [appsync.CfnGraphQLApi](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_appsync.CfnGraphQLApi.html) | ![Optional](https://img.shields.io/badge/optional-4169E1) | Existing merged api instance. The merge API provode a federated schema over source API schemas.|
6868

6969
## Pattern Properties
7070

src/patterns/gen-ai/aws-rag-appsync-stepfn-opensearch/index.ts

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ import * as targets from 'aws-cdk-lib/aws-events-targets';
2020
import * as iam from 'aws-cdk-lib/aws-iam';
2121
import * as lambda from 'aws-cdk-lib/aws-lambda';
2222
import * as logs from 'aws-cdk-lib/aws-logs';
23+
import * as opensearchservice from 'aws-cdk-lib/aws-opensearchservice';
2324
import * as s3 from 'aws-cdk-lib/aws-s3';
24-
import * as secrets from 'aws-cdk-lib/aws-secretsmanager';
25+
import * as secret from 'aws-cdk-lib/aws-secretsmanager';
2526
import * as stepfn from 'aws-cdk-lib/aws-stepfunctions';
2627
import * as stepfn_task from 'aws-cdk-lib/aws-stepfunctions-tasks';
2728
import { Construct } from 'constructs';
@@ -87,41 +88,29 @@ export interface RagAppsyncStepfnOpensearchProps {
8788
*/
8889
readonly bucketProcessedAssetsProps?: s3.BucketProps;
8990
/**
90-
* Domain name for the OpenSearch Service.
91-
*
92-
* @default - None
93-
*/
94-
readonly openSearchDomainName: string;
95-
/**
96-
* Domain endpoint for the OpenSearch Service.
97-
*
98-
* @default - None
99-
*/
100-
readonly openSearchDomainEndpoint: string;
91+
* Existing Amazon OpenSearch Service domain.
92+
*
93+
* @default - None
94+
*/
95+
readonly existinOpensearchDomain: opensearchservice.IDomain;
10196
/**
10297
* Index name for the OpenSearch Service.
10398
*
10499
* @default - None
105100
*/
106101
readonly openSearchIndexName: string;
107102
/**
108-
* SecretsManager secret id to access the OpenSearch Service.
109-
*
110-
* @default - None
111-
*/
112-
readonly openSearchSecretId: string;
113-
/**
114-
* URL endpoint of the appsync merged api.
115-
*
116-
* @default - None
117-
*/
118-
readonly mergedApiGraphQLEndpoint?: string;
103+
* SecretsManager secret to authenticate against the OpenSearch Service domain.
104+
*
105+
* @default - None
106+
*/
107+
readonly openSearchSecret: secret.ISecret;
119108
/**
120-
* ApiId of the appsync merged api.
109+
* Existing merged Appsync GraphQL api.
121110
*
122111
* @default - None
123112
*/
124-
readonly mergedApiGraphQLId?: string;
113+
readonly existingMergedApi?: appsync.CfnGraphQLApi;
125114
/**
126115
* Cognito user pool used for authentication.
127116
*
@@ -317,8 +306,8 @@ export class RagAppsyncStepfnOpensearch extends Construct {
317306

318307
// If the user provides a mergedApi endpoint, the lambda
319308
// functions will use this endpoint to send their status updates
320-
const updateGraphQlApiEndpoint = !props.mergedApiGraphQLEndpoint ? ingestion_graphql_api.graphqlUrl : props.mergedApiGraphQLEndpoint;
321-
const updateGraphQlApiId = !props.mergedApiGraphQLId ? ingestion_graphql_api.apiId : props.mergedApiGraphQLId;
309+
const updateGraphQlApiEndpoint = !props.existingMergedApi ? ingestion_graphql_api.graphqlUrl : props.existingMergedApi.attrGraphQlUrl;
310+
const updateGraphQlApiId = !props.existingMergedApi ? ingestion_graphql_api.apiId : props.existingMergedApi.attrApiId;
322311

323312
const job_status_data_source = new appsync.NoneDataSource(
324313
this,
@@ -453,15 +442,14 @@ export class RagAppsyncStepfnOpensearch extends Construct {
453442
OUTPUT_BUCKET: this.s3ProcessedAssetsBucketInterface.bucketName,
454443
GRAPHQL_URL: updateGraphQlApiEndpoint,
455444
OPENSEARCH_INDEX: props.openSearchIndexName,
456-
OPENSEARCH_DOMAIN_ENDPOINT: props.openSearchDomainEndpoint,
457-
OPENSEARCH_SECRET_ID: props.openSearchSecretId,
445+
OPENSEARCH_DOMAIN_ENDPOINT: props.existinOpensearchDomain.domainEndpoint,
446+
OPENSEARCH_SECRET_ID: props.openSearchSecret.secretName,
458447
},
459448
},
460449
);
461450

462451
// The lambda will access the opensearch credentials
463-
const openSearchSecret = secrets.Secret.fromSecretNameV2(this, 'openSearchSecret', props.openSearchSecretId);
464-
openSearchSecret.grantRead(embeddings_job_function);
452+
props.openSearchSecret.grantRead(embeddings_job_function);
465453

466454
// The lambda will pull processed files and create embeddings
467455
this.s3ProcessedAssetsBucket?.grantRead(embeddings_job_function);
@@ -470,8 +458,8 @@ export class RagAppsyncStepfnOpensearch extends Construct {
470458
effect: iam.Effect.ALLOW,
471459
actions: ['es:*'],
472460
resources: [
473-
'arn:aws:es:'+Aws.REGION+':'+Aws.ACCOUNT_ID+':domain/'+props.openSearchDomainName+'/*',
474-
'arn:aws:es:'+Aws.REGION+':'+Aws.ACCOUNT_ID+':domain/'+props.openSearchDomainName,
461+
'arn:aws:es:'+Aws.REGION+':'+Aws.ACCOUNT_ID+':domain/'+props.existinOpensearchDomain.domainName+'/*',
462+
'arn:aws:es:'+Aws.REGION+':'+Aws.ACCOUNT_ID+':domain/'+props.existinOpensearchDomain.domainName,
475463
],
476464
}));
477465

0 commit comments

Comments
 (0)