Navegue para a pasta que contém o arquivo main.tf
e baixe o arquivo zip contendo a função Lambda que será usada pelo Bedrock
cd challenge-day2/backend/src/lambda
cp list_products.zip ../../../../terraform-project/
cd ../../../../terraform-project
Adicione as linhas abaixo no final do arquivo main.tf
# IAM Role for Lambda function
resource "aws_iam_role" "lambda_role" {
name = "cloudmart_lambda_role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = "lambda.amazonaws.com"
}
}
]
})
}
# IAM Policy for Lambda function
resource "aws_iam_role_policy" "lambda_policy" {
name = "cloudmart_lambda_policy"
role = aws_iam_role.lambda_role.id
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = [
"dynamodb:Scan",
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
]
Resource = [
aws_dynamodb_table.cloudmart_products.arn,
aws_dynamodb_table.cloudmart_orders.arn,
aws_dynamodb_table.cloudmart_tickets.arn,
"arn:aws:logs:*:*:*"
]
}
]
})
}
# Lambda function for listing products
resource "aws_lambda_function" "list_products" {
filename = "list_products.zip"
function_name = "cloudmart-list-products"
role = aws_iam_role.lambda_role.arn
handler = "index.handler"
runtime = "nodejs20.x"
source_code_hash = filebase64sha256("list_products.zip")
environment {
variables = {
PRODUCTS_TABLE = aws_dynamodb_table.cloudmart_products.name
}
}
}
# Lambda permission for Bedrock
resource "aws_lambda_permission" "allow_bedrock" {
statement_id = "AllowBedrockInvoke"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.list_products.function_name
principal = "bedrock.amazonaws.com"
}
# Output the ARN of the Lambda function
output "list_products_function_arn" {
value = aws_lambda_function.list_products.arn
}
Siga estes passos para criar manualmente o Agente Bedrock para CloudMart:
<aside> 🔇
Atenção o vídeo abaixo não tem audio, apenas serve como referência no passo a passo.
</aside>
Screenshare - 2024-09-19 4_29_23 PM.mp4
No console Amazon Bedrock, escolha "Agents" em "Builder tools" no painel de navegação.
Clique em "Create agent".
Nomeie o agente "cloudmart-product-recommendation-agent".
Selecione "Claude 3 Sonnet" como o modelo base.
Cole as instruções do agente abaixo na seção "Instructions for the Agent".
You are a product recommendations agent for CloudMart, an online e-commerce store. Your role is to assist customers in finding products that best suit their needs. Follow these instructions carefully:
1. Begin each interaction by retrieving the full list of products from the API. This will inform you of the available products and their details.
2. Your goal is to help users find suitable products based on their requirements. Ask questions to understand their needs and preferences if they're not clear from the user's initial input.
3. Use the 'name' parameter to filter products when appropriate. Do not use or mention any other filter parameters that are not part of the API.
4. Always base your product suggestions solely on the information returned by the API. Never recommend or mention products that are not in the API response.
5. When suggesting products, provide the name, description, and price as returned by the API. Do not invent or modify any product details.
6. If the user's request doesn't match any available products, politely inform them that we don't currently have such products and offer alternatives from the available list.
7. Be conversational and friendly, but focus on helping the user find suitable products efficiently.
8. Do not mention the API, database, or any technical aspects of how you retrieve the information. Present yourself as a knowledgeable sales assistant.
9. If you're unsure about a product's availability or details, always check with the API rather than making assumptions.
10. If the user asks about product features or comparisons, use only the information provided in the product descriptions from the API.
11. Be prepared to assist with a wide range of product inquiries, as our e-commerce store may carry various types of items.
12. If a user is looking for a specific type of product, use the 'name' parameter to search for relevant items, but be aware that this may not capture all categories or types of products.
Remember, your primary goal is to help users find the best products for their needs from what's available in our store. Be helpful, informative, and always base your recommendations on the actual product data provided by the API.