Prerequisites
- Make sure there is a valid internet gateway and VPC set up.
- Ensure you have the Bedrock model Claude Sonnet available and activated.
- Make there is a valid IAM Identity with the following permissions
- AmazonBedrockFullAccess
- AmazonEC2FullAccess
- AmazonS3FullAccess
- AmazonSESFullAccess
-
Make sure to follow S3 Bucket naming convention AWS Console Setup
-
You must enable Claude Sonnet Model Access on AWS Console for Amazon Bedrock.
AWS CloudFormation
aws configure sso
aws cloudformation create-stack --stack-name $Stackname --template-url $Template_object_url --parameters ParameterKey=S3Bucket,ParameterValue=$S3BucketName ParameterKey=SESEmail,ParameterValue=$Email —profile $Profile (Profile parameter is optional)
- Ensure that the email verification is done. (A verification mail will be sent to the email that was given as a parameter.)
Steps to launch an AWS EC2 Instance
- Click 'Launch Instance' in the EC2 Console
- Provide a suitable name for the instance
- Choose Amazon Linux 2023 AMI and Architecture - 64-bit
- Instace type - t2.micro
- Choose a valid key pair name or create a new key pair
- Adjust network settings according to the setup vpc and subnet.
- Make sure to enable Auto-assign public IP and IPv6 IP
- Choose a suitable security group
- In Advanced Details, choose the IAM instance profile that follow the instructions of the prequisites.
- Add the following in the User data section:
Content-Type: multipart/mixed; boundary="//"
MIME-Version: 1.0
--//
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="cloud-config.txt"
#cloud-config
cloud_final_modules:
- [scripts-user, always]
--//
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="userdata.txt"
#!/bin/bash
# Update the instance and install screen
yum update -y
yum install -y screen
yum install -y python
yum install -y git
runuser -l ec2-user -c 'mkdir intelligent-request-collector'
git clone https://github.com/ASUCICREPO/intelligent-request-collector.git /home/ec2-user/intelligent-request-collector
yum install -y python-pip
cd /home/ec2-user/intelligent-request-collector
runuser -l ec2-user -c 'pip3 install --user -r /home/ec2-user/intelligent-request-collector/requirements.txt'
# Navigate to the project folder and start Streamlit in a detached screen session
runuser -l ec2-user -c 'cd /home/ec2-user/intelligent-request-collector'
runuser -l ec2-user -c 'screen -dmS my_streamlit_app bash -c "cd /home/ec2-user/intelligent-request-collector && streamlit run /home/ec2-user/intelligent-request-collector/main.py"'
# Output screen sessions list
echo "Streamlit app is running in a detached screen session named 'my_streamlit_app'."
echo "To view active screen sessions, run: screen -ls"
echo "To reattach to the Streamlit session, run: screen -r my_streamlit_app"
--//--
- Launch Instance
Connect to the EC2 Instance
- Choose the Launched EC2 Instance
- Connect using EC2 Instance Connect tab
- For connection type, choose 'Connect using EC2 Instance Connect'
- Choose Public IPv4 address
- Make sure the username is 'ec2-user'.
- Click Connect
In the EC2 Instance
- Traverse to the intelligent-resource-collector dir
cd intelligent-resource-collector
- create .env and edit the .env file
nano .env
- Edit the .env file with the appropriate values. BUCKET_NAME and FROM_EMAIL are the only required ones; the region name should default to us-east-1.
REGION_NAME=$RegionName BUCKET_NAME=$BucketName FROM_EMAIL=$SESEmail DYNAMODB_TABLE_NAME=""
- Save and exit the .env file
Ctrl + X y Enter
- View the .env file
cat .env
Note: The rest of the documentations provides commands to manage any Screen/Streamlit sessions
Run Streamlit with Screen
- Create a Screen Session
screen -S my_streamlit_app
- After entering the Session, Traverse to root folder
cd intelligent-request-collector
- Run streamlit
streamlit run main.py
- Detach from the session:
Ctrl + A, then D
- You can now run the session after exiting the Instance
Shutdown Streamlit app
- After entering the instance, you can view the screen sessions using:
screen -ls
- Reattach to the intended session.
screen -r my_streamlit_app
- Stop the session
Ctrl + C
- Exit Screen Session
exit
Run it
streamlit run main.py
Architecture
This prototype utilizes streamlit to provide the user a frontend experience.
AWS Services that are utilized by this prototype:
- Amazon Bedrock (Generative AI Functionality)
- Amazon SES (Email functionality)
- Amazon S3 (File attachment storage)
- Amazon EC2 (Frontend)