aws-samples / amazon-bedrock-samples

This repository contains examples for customers to get started using the Amazon Bedrock Service. This contains examples for all available foundational models
https://aws.amazon.com/bedrock/
MIT No Attribution
439 stars 233 forks source link

error deploying `bedrock-agent-cdk` example #40

Closed jritsema closed 8 months ago

jritsema commented 8 months ago

I got the following error when following the instructions in bedrock-agent-cdk. /cc: @rppth

cdk bootstrap
/Users/jritsema/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:859
    return new TSError(diagnosticText, diagnosticCodes, diagnostics);
           ^
TSError: ⨯ Unable to compile TypeScript:
bin/bedrock-agent-cdk.ts:3:23 - error TS2307: Cannot find module 'path' or its corresponding type declarations.

3 import * as path from 'path';
                        ~~~~~~
bin/bedrock-agent-cdk.ts:4:23 - error TS2307: Cannot find module 'glob' or its corresponding type declarations.

4 import * as glob from 'glob';
                        ~~~~~~
bin/bedrock-agent-cdk.ts:5:22 - error TS2307: Cannot find module 'aws-cdk-lib' or its corresponding type declarations.

5 import * as cdk from 'aws-cdk-lib';
                       ~~~~~~~~~~~~~

    at createTSError (/Users/jritsema/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:859:12)
    at reportTSError (/Users/jritsema/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:863:19)
    at getOutput (/Users/jritsema/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:1077:36)
    at Object.compile (/Users/jritsema/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:1433:41)
    at Module.m._compile (/Users/jritsema/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:1617:30)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Object.require.extensions.<computed> [as .ts] (/Users/jritsema/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Function.Module._load (node:internal/modules/cjs/loader:960:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
  diagnosticCodes: [ 2307, 2307, 2307 ]
}

Here are my dependencies

cdk --version
2.113.0 (build ccd534a)

node --version
v18.17.1

npm --version
9.6.7
maxtybar commented 8 months ago

Hi @jritsema, could you run npm install before cdk bootstrap from within the same root directory (bedrock-agent-cdk)? We will update this in the README. Thank you.

jritsema commented 8 months ago

I had tried that.

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: @aws-cdk/aws-lambda-python-alpha@2.108.0-alpha.0
npm ERR! Found: aws-cdk-lib@2.87.0
npm ERR! node_modules/aws-cdk-lib
npm ERR!   aws-cdk-lib@"2.87.0" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer aws-cdk-lib@"^2.108.0" from @aws-cdk/aws-lambda-python-alpha@2.108.0-alpha.0
npm ERR! node_modules/@aws-cdk/aws-lambda-python-alpha
npm ERR!   @aws-cdk/aws-lambda-python-alpha@"^2.108.0-alpha.0" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: aws-cdk-lib@2.113.0
npm ERR! node_modules/aws-cdk-lib
npm ERR!   peer aws-cdk-lib@"^2.108.0" from @aws-cdk/aws-lambda-python-alpha@2.108.0-alpha.0
npm ERR!   node_modules/@aws-cdk/aws-lambda-python-alpha
npm ERR!     @aws-cdk/aws-lambda-python-alpha@"^2.108.0-alpha.0" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

Also another thing I had to add.

--- a/agents/bedrock-agent-cdk/tsconfig.json
+++ b/agents/bedrock-agent-cdk/tsconfig.json
@@ -20,6 +20,7 @@
     "inlineSources": true,
     "experimentalDecorators": true,
     "strictPropertyInitialization": false,
+    "types": ["node"],
     "typeRoots": [
       "./node_modules/@types"
     ]
maxtybar commented 8 months ago

@jritsema I have update README so you can find more information about that. There is also no need for @aws-lambda-python-alpha construct and no need for Docker. And you shouldn't need to add anything extra. Please make sure you copied the lates updated repository and if you face the same issue run npm install --force. Let me know if that helps.

jritsema commented 8 months ago

Great! Seems to be working now. Thanks @maxtybar!

jritsema commented 8 months ago

One other question @maxtybar. Where is the intended place to iterate on the agent instruction? Is it here? Might be nice to maintain at the top level as it is as key differentiated piece of info that lives alongside the schema and the implementation.

maxtybar commented 8 months ago

@jritsema Yes, you are correct, it is inside cdk-resource-bedrock-agent.py file. I actually did not intend to expose this because it was meant to serve just as an example of how you could deploy your agent and later be able to edit your agent's information (such as instruction, alias, version, etc.) in the AWS console. We have more robust, though not as customizable, agent deployment samples (such as this). Also, feel free to explore a full AWS CDK Construct here that has a better agent implementation that you could incorporate in your AWS CDK code. In the meantime, thank you for the feedback and I will incorporate it in the update!