Gestione di progetti con AWS CloudFormation - Amazon Bedrock

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

Gestione di progetti con AWS CloudFormation

Amazon Bedrock è integrato con AWS CloudFormation e ti consente di definire e gestire progetti come parte dei tuoi modelli di infrastruttura. Puoi effettuare il provisioning di progetti in modo coerente e ripetuto su più account e regioni AWS utilizzando modelli JSON o YAML.

AWS::BedrockMantle::Project

Usa la AWS::BedrockMantle::Project risorsa per creare e gestire un progetto Bedrock in un modello. CloudFormation I progetti creati tramite CloudFormation supportano le stesse funzionalità di quelli creati tramite l'API, tra cui l'allegazione, l'etichettatura e l'osservabilità delle policy IAM.

Sintassi

Per dichiarare questa entità nel CloudFormation modello, utilizza la seguente sintassi:

Esempio CloudFormation Sintassi
{ "Type": "AWS::BedrockMantle::Project", "Properties": { "Name": String, "Tags": [ { "Key": String, "Value": String }, { "Key": String, "Value": String }, { "Key": String, "Value": String }, { "Key": String, "Value": String } ] } }
Type: AWS::BedrockMantle::Project Properties: Name: String Tags: Key: Value

Properties

Name

Obbligatorio. Il nome del progetto. Deve essere unico all'interno del tuo account AWS.

Tipo: String

Minimo: 1

Massimo: 64

Modello: ^([0-9a-zA-Z][ _-]?)+$

Aggiornamento richiesto: sostituzione

Tag

Una mappa di coppie chiave-valore da associare al progetto per l'allocazione dei costi e il controllo degli accessi.

Tipo: Map di String

L'aggiornamento richiede: nessuna interruzione

Nota sugli aggiornamenti dei tag

CloudFormation gli aggiornamenti dei tag AWS::BedrockMantle::Project utilizzano operazioni di aggiunta e rimozione separate internamente. Non è prevista la sostituzione completa del tag atomico. Se un aggiornamento dello stack fallisce durante l'operazione, il set di tag del progetto potrebbe trovarsi in uno stato parzialmente aggiornato. Verifica sempre lo stato finale del tag dopo un aggiornamento dello stack che modifica i tag.

Valori restituiti

Ref

Quando si passa l'ID logico di questa risorsa alla Ref funzione intrinseca, Ref restituisce l'ID del progetto (ad esempio,). proj_abc123

Fn:: GetAtt

ProjectId

L'identificatore univoco del progetto (ad es.). proj_abc123

ProjectArn

L'Amazon Resource Name (ARN) del progetto (ad es.). arn:aws:bedrock-mantle:us-east-1:123456789012:project/proj_abc123

Status

Lo stato del progetto. ACTIVEindica che il progetto è pronto per l'uso. ARCHIVEDsignifica che il progetto è stato archiviato e non può accettare nuove richieste di inferenza.

CreatedAt

Il timestamp in cui è stato creato il progetto.

UpdatedAt

Il timestamp in cui il progetto è stato aggiornato l'ultima volta.

Esempi

Crea un progetto di base

L'esempio seguente crea un progetto per un'applicazione chatbot di produzione:

Esempio Progetto di base
AWSTemplateFormatVersion: '2010-09-09' Description: Amazon Bedrock Project for Production Chatbot Resources: CustomerChatbotProject: Type: AWS::BedrockMantle::Project Properties: Name: CustomerChatbot-Production Tags: - Key: Project Value: CustomerChatbot - Key: Environment Value: Production - Key: Owner Value: TeamAlpha - Key: CostCenter Value: "21524" Outputs: ProjectId: Description: The ID of the created project Value: !Ref CustomerChatbotProject ProjectArn: Description: The ARN of the created project Value: !GetAtt CustomerChatbotProject.ProjectArn
{ "AWSTemplateFormatVersion": "2010-09-09", "Resources": { "CustomerChatbotProject": { "Type": "AWS::BedrockMantle::Project", "Properties": { "Name": "CustomerChatbot-Production", "Tags": [ { "Key": "Project", "Value": "CustomerChatbot" }, { "Key": "Environment", "Value": "Production" }, { "Key": "Owner", "Value": "TeamAlpha" }, { "Key": "CostCenter", "Value": "21524" } ] } } }, "Outputs": { "ProjectId": { "Description": "The ID of the created project", "Value": { "Ref": "CustomerChatbotProject" } }, "ProjectArn": { "Description": "The ARN of the created project", "Value": { "Fn::GetAtt": ["CustomerChatbotProject", "ProjectArn"] } } } }

Crea più progetti per ambienti diversi

L'esempio seguente fornisce progetti separati per ambienti di sviluppo, staging e produzione in un unico stack:

AWSTemplateFormatVersion: '2010-09-09' Description: Amazon Bedrock Projects for Multi-Environment Deployment Parameters: ApplicationName: Type: String Default: InternalSearch Description: Name of the application CostCenter: Type: String Description: Cost center for billing allocation Resources: DevelopmentProject: Type: AWS::BedrockMantle::Project Properties: Name: !Sub "${ApplicationName}-Development" Tags: - Key: Project Value: !Ref ApplicationName - Key: Environment Value: Development - Key: CostCenter Value: !Ref CostCenter StagingProject: Type: AWS::BedrockMantle::Project Properties: Name: !Sub "${ApplicationName}-Staging" Tags: - Key: Project Value: !Ref ApplicationName - Key: Environment Value: Staging - Key: CostCenter Value: !Ref CostCenter ProductionProject: Type: AWS::BedrockMantle::Project Properties: Name: !Sub "${ApplicationName}-Production" Tags: - Key: Project Value: !Ref ApplicationName - Key: Environment Value: Production - Key: CostCenter Value: !Ref CostCenter Outputs: DevelopmentProjectArn: Value: !GetAtt DevelopmentProject.ProjectArn Export: Name: !Sub "${ApplicationName}-Dev-ProjectArn" StagingProjectArn: Value: !GetAtt StagingProject.ProjectArn Export: Name: !Sub "${ApplicationName}-Staging-ProjectArn" ProductionProjectArn: Value: !GetAtt ProductionProject.ProjectArn Export: Name: !Sub "${ApplicationName}-Prod-ProjectArn"

Crea un progetto con IAM Role Access

L'esempio seguente crea un progetto e allega una policy IAM che concede a un ruolo specifico l'accesso ai modelli di invocazione:

AWSTemplateFormatVersion: '2010-09-09' Description: Amazon Bedrock Project with IAM Access Control Resources: ProductionProject: Type: AWS::BedrockMantle::Project Properties: Name: CustomerChatbot-Production Tags: - Key: Environment Value: Production - Key: CostCenter Value: "21524" ProductionAppRole: Type: AWS::IAM::Role Properties: RoleName: BedrockProjectProductionRole AssumeRolePolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Principal: Service: lambda.amazonaws.com Action: sts:AssumeRole Policies: - PolicyName: BedrockProjectInvokeAccess PolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Action: - bedrock-mantle:CreateInference - bedrock-mantle:GetProject Resource: !GetAtt ProductionProject.ProjectArn Outputs: ProjectArn: Value: !GetAtt ProductionProject.ProjectArn RoleArn: Value: !GetAtt ProductionAppRole.Arn

Utilizzo degli CloudFormation output con l'API Projects

Dopo aver distribuito lo CloudFormation stack, puoi fare riferimento all'ARN e all'ID del progetto nel codice dell'applicazione utilizzando gli output dello stack:

import boto3 from openai import OpenAI # Retrieve project details from CloudFormation stack outputs cfn = boto3.client('cloudformation', region_name='us-east-1') response = cfn.describe_stacks(StackName='my-bedrock-projects-stack') outputs = {o['OutputKey']: o['OutputValue'] for o in response['Stacks'][0]['Outputs']} production_project_arn = outputs['ProductionProjectArn'] # Extract project ID from ARN # ARN format: arn:aws:bedrock-mantle:us-east-1:123456789012:project/proj_abc123 project_id = production_project_arn.split('/')[-1] print(f"Using project: {project_id}") # Use the project for inference client = OpenAI(project=project_id) response = client.responses.create( model="openai.gpt-oss-120b", input="Hello from a CloudFormation-managed project!" ) print(response)

Ulteriori informazioni

Per ulteriori informazioni sull'utilizzo CloudFormation con le risorse Amazon Bedrock, consulta: