Skip to content

Commit 68c5eee

Browse files
committed
feat(bda): add new sample
1 parent 3dcfbb4 commit 68c5eee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+22236
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ This repo provides samples to demonstrate how to build your own Generative AI so
1717
|[Python Samples](samples/python-samples/)| This project showcases the utilization of the 'generative-ai-cdk-constructs' package from the Python Package Index (PyPI).| Backend | Python|
1818
|[.NET Samples](samples/dotnet-samples/)| This project showcases the utilization of the 'Cdklabs.GenerativeAiCdkConstructs' package from nuget library.| Backend | .NET|
1919
|[Contract Compliance Analysis](samples/contract-compliance-analysis/)| This project automates the analysis of contracts by splitting them into clauses, determining clause types, evaluating compliance against a customer's legal guidelines, and assessing overall contract risk based on the number of compliant clauses. This is achieved through a workflow that leverages Large Language Models via Amazon Bedrock. | Backend + Frontend | Python for Backend, TypeScript (React) for Frontend |
20+
|[Multimodal RAG solution](samples/multimodal-rag)| This project showcases Amazon Bedrock multimodal features using [Amazon Bedrock Data Automation](https://aws.amazon.com/bedrock/bda/) (BDA) combined with Amazon Bedrock Knowledge Bases for a RAG-based chatbot. | Backend + Frontend | Python for Backend, TypeScript (React) for Frontend |
2021
|[RFP Answers with GenAI](samples/rfp-answer-generation/)| This project provides guidance on how you can use Knowledge Bases for Amazon Bedrock with custom transformations to create draft answers for Request for Proposal (RFP) documents, streamlining the answer of new potential contracts. This is achieved through a workflow that leverages Large Language Models via Amazon Bedrock. | Backend + Frontend | Python for Backend, TypeScript (React) for Frontend |
2122
| [Code Expert](samples/code-expert/) | This project addresses the scalability limitations of manual code reviews by leveraging artificial intelligence to perform expert code reviews automatically. It leverages the [Bedrock Batch Step Functions CDK construct](https://github.com/awslabs/generative-ai-cdk-constructs/blob/main/src/patterns/gen-ai/aws-bedrock-batch-stepfn/README.md). | Backend | Python for Backend and Demo, TypeScript for CDK |
2223
|[Bedrock Agent UI Wrapper](samples/bedrock-agent-ui-wrapper/)| This sample provides a CDK construct that creates an API layer and frontend application for Amazon Bedrock Agents. It includes authentication with Amazon Cognito, agent trace streaming, and can be deployed locally or on ECS Fargate. | API layer + Frontend | Python|

samples/multimodal-rag/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

samples/multimodal-rag/README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Bedrock BDA Multimodal Media Solution
2+
3+
## Table of contents
4+
5+
- [Overview](#overview)
6+
- [Architecture](#architecture)
7+
- [Folder structure](#folder-structure)
8+
- [Getting Started](#getting-started)
9+
- [Content Security Legal Disclaimer](#content-security-legal-disclaimer)
10+
- [Service Quotas](#service-quotas)
11+
- [Operational Metrics Collection](#operational-metrics-collection)
12+
13+
## Overview
14+
15+
This demo showcases the Amazon Bedrock multimodal features applied to media and advertising use cases, including [Amazon Bedrock Data Automation](https://aws.amazon.com/bedrock/bda/) (BDA). It highlights several popular media applications, such as BDA for video metadata extraction, BDA for contextual advertising analysis, BDA combined with Bedrock Knowledge Bases for a RAG-based chatbot.
16+
17+
> Warning
18+
>
19+
> Amazon Bedrock Data Automation is currently GA, and is available only in regions us-west-2 and us-east-1. More information available in the
20+
> [official blog post](https://aws.amazon.com/blogs/machine-learning/simplify-multimodal-generative-ai-with-amazon-bedrock-data-automation/)
21+
22+
- No real personal/sensitive information included
23+
- For testing/development purposes only
24+
25+
## Architecture
26+
27+
![High Level Architecture](./images/BedrockBDAMediaSolution.png)
28+
29+
Here's the data flow explanation for the AWS architecture above:
30+
31+
- User initiates interaction with the system (for instance, through the provided frontend)
32+
- User authentication via Amazon Cognito is performed, user operations are managed through Amazon API Gateway. Amazon API Gateway forwards requests to AWS Lambda for processing
33+
- When media files are uploaded, an Amazon Bedrock Data Automation (BDA) process is initiated to process the input files. Amazon DynamoDB is used to track operations.
34+
Amazon BDA job status is tracked through Amazon EventBridge. Once completed, an event triggers an AWS Lambda function which parses the output files from BDA and prepares them for Amazon Bedrock Knowledge Base. BDA Results are stored in Amazon S3 (Simple Storage Service).
35+
36+
## Folder Structure
37+
38+
This sample application codebase is organized into these key folders:
39+
40+
```
41+
samples/bedrock-bda-media-solution
42+
43+
├── backend # Backend architecture CDK project
44+
├── images # Images used for documentation
45+
└── frontend # Frontend sample application
46+
```
47+
48+
## Getting started
49+
50+
To deploy this project, follow the [instructions available in the `backend` folder](./backend/README.md).
51+
52+
You can also use the provided frontend by following the [instructions available in the `frontend` folder](./frontend/README.md).
53+
54+
## Content Security Legal Disclaimer
55+
56+
The sample code; software libraries; command line tools; proofs of concept; templates; or other related technology (including any of the foregoing that are provided by our personnel) is provided to you as AWS Content under the AWS Customer Agreement, or the relevant written agreement between you and AWS (whichever applies). You should not use this AWS Content in your production accounts, or on production or other critical data. You are responsible for testing, securing, and optimizing the AWS Content, such as sample code, as appropriate for production grade use based on your specific quality control practices and standards. Deploying AWS Content may incur AWS charges for creating or using AWS chargeable resources, such as running Amazon EC2 instances or using Amazon S3 storage.
57+
58+
## Service Quotas
59+
60+
Your AWS account has default quotas, also known as service limits, described [here](https://docs.aws.amazon.com/general/latest/gr/aws_service_limits.html). This sample can be installed and tested within the default quotas for each of the services used. You can request increases for some quotas. Note that not all quotas can be increased.
61+
62+
To operate this sample at scale, it is important to monitor your usage of AWS services and configure alarm settings to notify you when a quota is close to being exceeded. You can find details on visualizing your service quotas and setting alarms [here](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Quotas-Visualize-Alarms.html).
63+
64+
## Operational Metrics Collection
65+
66+
Generative AI CDK Constructs samples may collect anonymous operational metrics, including: the region a construct is deployed, the name and version of the construct deployed, and related information. We may use the metrics to maintain, provide, develop, and improve the constructs and AWS services.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
*.swp
2+
package-lock.json
3+
__pycache__
4+
.pytest_cache
5+
.venv
6+
*.egg-info
7+
8+
# CDK asset staging directory
9+
.cdk.staging
10+
cdk.out
11+
12+
### macOS ###
13+
# General
14+
.DS_Store
15+
.AppleDouble
16+
.LSOverride
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# Bedrock BDA Multimodal Media Solution - Backend
2+
3+
## Table of contents
4+
5+
- [Local deployment](#local-deployment)
6+
- [User creation](#user-creation)
7+
8+
## Local deployment
9+
10+
In order to deploy this project, you need to have installed:
11+
12+
- [Python](https://www.python.org/downloads/) 3.11 or higher
13+
- [Docker](https://docs.docker.com/engine/install/)
14+
- Git (if using code repository)
15+
- [AWS CDK Toolkit](https://docs.aws.amazon.com/cdk/v2/guide/cli.html)
16+
- [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html)
17+
18+
With all installed, run this command:
19+
20+
```shell
21+
$ python3 -V && cdk --version && docker info -f "{{.OperatingSystem}}"
22+
Python 3.12.2
23+
2.176.0 (build 899965d)
24+
Docker Desktop
25+
```
26+
27+
An output similar to the above indicates that all is ok to proceed.
28+
29+
If any of these commands fails, you can revisit the documentation and check for possible steps you have forgotten to complete.
30+
Ensure that your CDK version is using CDK V2, by checking if the second line of the output follows the pattern 2.*.*.
31+
32+
Having those installed, it is time to configure your environment to connect to your AWS Account.
33+
To set up your local environment to use such an AWS account you can follow the steps described at [https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html)
34+
35+
### Get source code
36+
37+
If not done already, clone this repository
38+
39+
```shell
40+
git clone https://github.com/aws-samples/generative-ai-cdk-constructs-samples.git
41+
```
42+
43+
Enter the backend directory
44+
45+
```shell
46+
cd samples/bedrock-bda-media-solution/backend
47+
```
48+
49+
### Create Python virtual environment
50+
51+
To manually create a virtualenv on MacOS and Linux:
52+
53+
```shell
54+
python3 -m venv .venv
55+
```
56+
57+
After the init process completes and the virtualenv is created, you can use the following
58+
step to activate your virtualenv.
59+
60+
```shell
61+
source .venv/bin/activate
62+
```
63+
64+
If you are a Windows platform, you would activate the virtualenv like this:
65+
66+
```shell
67+
.venv\Scripts\activate.bat
68+
```
69+
70+
Once the virtualenv is activated, you can install the required dependencies.
71+
72+
```shell
73+
pip install -r requirements.txt
74+
```
75+
76+
### Bootstrap CDK
77+
78+
Run the following
79+
80+
```shell
81+
cdk bootstrap
82+
```
83+
84+
### Deployment
85+
86+
1. Run AWS CDK Toolkit to deploy the Backend stack with the runtime resources.
87+
88+
```shell
89+
cdk deploy --require-approval=never
90+
```
91+
92+
2. Any modifications made to the code can be applied to the deployed stack by running the same command again.
93+
94+
```shell
95+
cdk deploy --require-approval=never
96+
```
97+
98+
## Samples files
99+
100+
The [samples](./samples/) folder contains samples files you can use to test the application.
101+
102+
## User creation
103+
104+
First, locate the Cognito User Pool ID, through the AWS CLI:
105+
106+
```shell
107+
$ aws cloudformation describe-stacks --stack-name BDAMediaSolutionBackendStack --query "Stacks[0].Outputs[?contains(OutputKey, 'UserPoolId')].OutputValue"
108+
109+
[
110+
"OutputValue": "<region>_a1aaaA1Aa"
111+
]
112+
```
113+
114+
You can then go the Amazon Cognito page at the AWS Console, search for the User Pool and add users.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
6+
# with the License. A copy of the License is located at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES
11+
# OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions
12+
# and limitations under the License.
13+
#
14+
15+
import aws_cdk as cdk
16+
from cdk_nag import AwsSolutionsChecks
17+
from stack import BackendStack
18+
19+
USAGE_METRIC = 'uksb-1tupboc45'
20+
SOLUTION_NAME = "Bedrock BDA Media Solution"
21+
22+
app = cdk.App()
23+
BackendStack(
24+
app,
25+
"BDAMediaSolutionBackendStack",
26+
description=f'({USAGE_METRIC})(tag: {SOLUTION_NAME})'
27+
)
28+
29+
cdk.Aspects.of(app).add(AwsSolutionsChecks())
30+
31+
app.synth()
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{
2+
"app": "python3 app.py",
3+
"watch": {
4+
"include": [
5+
"**"
6+
],
7+
"exclude": [
8+
"README.md",
9+
"cdk*.json",
10+
"requirements*.txt",
11+
"source.bat",
12+
"**/__init__.py",
13+
"**/__pycache__",
14+
"tests"
15+
]
16+
},
17+
"context": {
18+
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
19+
"@aws-cdk/core:checkSecretUsage": true,
20+
"@aws-cdk/core:target-partitions": [
21+
"aws",
22+
"aws-cn"
23+
],
24+
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
25+
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
26+
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
27+
"@aws-cdk/aws-iam:minimizePolicies": true,
28+
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
29+
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
30+
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
31+
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
32+
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
33+
"@aws-cdk/core:enablePartitionLiterals": true,
34+
"@aws-cdk/aws-events:eventsTargetQueueSameAccount": true,
35+
"@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true,
36+
"@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true,
37+
"@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true,
38+
"@aws-cdk/aws-route53-patters:useCertificate": true,
39+
"@aws-cdk/customresources:installLatestAwsSdkDefault": false,
40+
"@aws-cdk/aws-rds:databaseProxyUniqueResourceName": true,
41+
"@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true,
42+
"@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": true,
43+
"@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true,
44+
"@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true,
45+
"@aws-cdk/aws-redshift:columnId": true,
46+
"@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": true,
47+
"@aws-cdk/aws-ec2:restrictDefaultSecurityGroup": true,
48+
"@aws-cdk/aws-apigateway:requestValidatorUniqueId": true,
49+
"@aws-cdk/aws-kms:aliasNameRef": true,
50+
"@aws-cdk/aws-autoscaling:generateLaunchTemplateInsteadOfLaunchConfig": true,
51+
"@aws-cdk/core:includePrefixInUniqueNameGeneration": true,
52+
"@aws-cdk/aws-efs:denyAnonymousAccess": true,
53+
"@aws-cdk/aws-opensearchservice:enableOpensearchMultiAzWithStandby": true,
54+
"@aws-cdk/aws-lambda-nodejs:useLatestRuntimeVersion": true,
55+
"@aws-cdk/aws-efs:mountTargetOrderInsensitiveLogicalId": true,
56+
"@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters": true,
57+
"@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier": true,
58+
"@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": true,
59+
"@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": true,
60+
"@aws-cdk/aws-cloudwatch-actions:changeLambdaPermissionLogicalIdForLambdaAction": true,
61+
"@aws-cdk/aws-codepipeline:crossAccountKeysDefaultValueToFalse": true,
62+
"@aws-cdk/aws-codepipeline:defaultPipelineTypeToV2": true,
63+
"@aws-cdk/aws-kms:reduceCrossAccountRegionPolicyScope": true,
64+
"@aws-cdk/aws-eks:nodegroupNameAttribute": true,
65+
"@aws-cdk/aws-ec2:ebsDefaultGp3Volume": true,
66+
"@aws-cdk/aws-ecs:removeDefaultDeploymentAlarm": true,
67+
"@aws-cdk/custom-resources:logApiResponseDataPropertyTrueDefault": false,
68+
"@aws-cdk/aws-s3:keepNotificationInImportedBucket": false,
69+
"@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature": false,
70+
"@aws-cdk/aws-ecs:disableEcsImdsBlocking": true,
71+
"@aws-cdk/aws-ecs:reduceEc2FargateCloudWatchPermissions": true,
72+
"@aws-cdk/aws-dynamodb:resourcePolicyPerReplica": true,
73+
"@aws-cdk/aws-ec2:ec2SumTImeoutEnabled": true,
74+
"@aws-cdk/aws-appsync:appSyncGraphQLAPIScopeLambdaPermission": true,
75+
"@aws-cdk/aws-rds:setCorrectValueForDatabaseInstanceReadReplicaInstanceResourceId": true,
76+
"@aws-cdk/core:cfnIncludeRejectComplexResourceUpdateCreatePolicyIntrinsics": true,
77+
"@aws-cdk/aws-lambda-nodejs:sdkV3ExcludeSmithyPackages": true,
78+
"@aws-cdk/aws-stepfunctions-tasks:fixRunEcsTaskPolicy": true,
79+
"@aws-cdk/aws-ec2:bastionHostUseAmazonLinux2023ByDefault": true,
80+
"@aws-cdk/aws-route53-targets:userPoolDomainNameMethodWithoutCustomResource": true,
81+
"@aws-cdk/aws-elasticloadbalancingV2:albDualstackWithoutPublicIpv4SecurityGroupRulesDefault": true
82+
}
83+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
aws-cdk-lib==2.188.0
2+
aws_cdk.aws_lambda_python_alpha==2.188.0a0
3+
constructs>=10.0.0,<11.0.0
4+
cdk_nag==2.35.62
5+
aws_solutions_constructs.aws_eventbridge_lambda==2.81.0
6+
cdklabs.generative-ai-cdk-constructs==0.1.300
15 MB
Binary file not shown.
1.58 MB
Loading

0 commit comments

Comments
 (0)