Original Author Tarek Kaddoumi, Senior Solutions Architect at Amazon Web Services (AWS)
Original file: Bedrock/main.js
I did my own modification on this real-world project build with Amazon Web Services (AWS) đź“™
I will bring more real-world projects with AWS.
-
Install “virtualenv” package if not already installed.
pip install virtualenv
-
Set up virtual environment
virtualenv venv
-
Activate virtual environment
source venv/bin/activate
-
Deactivate virtual environment
deactivate
orsource deactivate
Let's try the app by installing dependencies and running it.
-
Go in to the project folder
cd my-affirmations
(VUE 3 + TypeScript + Vite). Install the dependencies first using the Terminal. If the terminal is not visible, select TERMINAL from the Panel. If the Panel is closed, select menu item View and Terminal to show it. -
In the terminal, run:
npm install
-
When the install has finished, it's time to run the app for the first time.
-
In the terminal, run
npm run dev
-
A popup message may appear asking if you want to open the app in the browser, select this or select the network URL that is displayed in the terminal
-
-
Ensure the app loads and you can see the web page is rendered and you can click on the button.
Additional: Build Vite Project: Run npm run build
to generate the production-ready assets in the dist
folder.
The next section ensures your app can communicate with AWS to use Amazon Bedrock.
Your Workshop Studio account is configured with an access key and secret to provide authorisation to access Amazon Bedrock service.
AWS Access Keys and Secrets: Best Practices for Development and Deployment
As this app will only be running in VS Code Server and will not be deployed, we are using an IAM user's Access Key and Secret environment variables to access Amazon Bedrock securely. This is not how we would secure a production app that was going to be deployed, but the focus in this lab is on working with Bedrock APIs, so we are using this simpler approach. If you are interested in learning more about security and best practices, review the links below after the lab.
-
In Visual Studio Code Server, open the .env file (if it doesn't exist, creat one). This file stores your environment variables so you can access Amazon Bedrock securely. No need VITE_AWS_SESSION_TOKEN.
VITE_AWS_DEFAULT_REGION= VITE_AWS_ACCESS_KEY_ID= VITE_AWS_SECRET_ACCESS_KEY=
-
Only environment variables starting with VITE_ are exposed to the app.
-
To populate these with actual values, switch over to the AWS Workshop Studio event dashboard.
-
Select Get AWS CLI credentials.
-
An AWS account access dialog will open.
-
Select the fourth tab Windows (CMD). Even if you are not using Windows, this is the easiest one to choose.
-
Select the copy icon to copy the values to your clipboard. Alternatively you can select and copy them manually if that button does not work on your web browser.
-
Switch back to the VS Code window. In the .env file paste the environment variables you just copied below the existing lines of code.
-
Your .env file will look something like this:
VITE_AWS_DEFAULT_REGION= VITE_AWS_ACCESS_KEY_ID= VITE_AWS_SECRET_ACCESS_KEY= set AWS_DEFAULT_REGION=us-west-2 set AWS_ACCESS_KEY_ID=ABCDEFIGHIGJ set AWS_SECRET_ACCESS_KEY=ABCDEFIGHIGJKLMNOPQRSTUVWXYZ
-
Please note that the variable values above are samples, do not copy these into your own files, as they will not work.
-
Now comes the trickiest step in the entire lab:
- Every key starting with AWS_ has a matching key starting with VITE_AWS_.
- The variable is the part following the =, and should not have any quotes or brackets or anything else, just a string of characters.
-
Your choice is either:
- The variables need to be moved (or copied and pasted) from the AWS_ lines to the corresponding VITE_AWS_ lines.or
- Remove the set and paste the prefixÂ
VITE_
 in front of each AWS_ key.
The end result should look like this, regardless of which method you use:
VITE_AWS_DEFAULT_REGION=us-west-2
VITE_AWS_ACCESS_KEY_ID=ABCDEFIGHIGJ
VITE_AWS_SECRET_ACCESS_KEY=ABCDEFIGHIGJKLMNOPQRSTUVWXYZ