Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.
Mengelola Proyek dengan AWS CloudFormation
Amazon Bedrock terintegrasi dengan AWS CloudFormation, memungkinkan Anda menentukan dan mengelola Proyek sebagai bagian dari templat infrastruktur Anda. Anda dapat menyediakan proyek secara konsisten dan berulang kali di beberapa akun AWS dan Wilayah menggunakan templat JSON atau YAMAL.
AWS::BedrockMantle::Project
Gunakan AWS::BedrockMantle::Project sumber daya untuk membuat dan mengelola Proyek Batuan Dasar dalam CloudFormation template. Proyek yang dibuat melalui CloudFormation dukungan kemampuan yang sama seperti yang dibuat melalui API, termasuk lampiran kebijakan IAM, penandaan, dan observabilitas.
Sintaksis
Untuk mendeklarasikan entitas ini di CloudFormation template Anda, gunakan sintaks berikut:
contoh CloudFormation Sintaks
{ "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
Sifat-sifat
- Nama
-
Wajib. Nama proyek. Harus unik dalam akun AWS Anda.
Tipe: String
Minimal: 1
Maksimal: 64
Pola:
^([0-9a-zA-Z][ _-]?)+$Pembaruan membutuhkan: Penggantian
- Tag
-
Peta pasangan kunci-nilai untuk dikaitkan dengan proyek untuk alokasi biaya dan kontrol akses.
Jenis: Peta String
Pembaruan memerlukan: Tidak ada gangguan
Catatan tentang Pembaruan Tag
CloudFormation tag pembaruan pada AWS::BedrockMantle::Project penggunaan operasi tambah dan hapus terpisah secara internal. Tidak ada penggantian tag penuh atom. Jika pembaruan tumpukan gagal di tengah operasi, kumpulan tag proyek mungkin dalam status yang diperbarui sebagian. Selalu verifikasi status tag akhir setelah pembaruan tumpukan yang memodifikasi tag.
Nilai Pengembalian
Ref
Ketika Anda meneruskan ID logis dari sumber daya ini ke Ref fungsi intrinsik, Ref mengembalikan ID proyek (misalnya,proj_abc123).
Fn:: GetAtt
- ProjectId
-
Pengidentifikasi unik proyek (misalnya,
proj_abc123). - ProjectArn
-
Nama Sumber Daya Amazon (ARN) proyek (misalnya,
arn:aws:bedrock-mantle:us-east-1:123456789012:project/proj_abc123). - Status
-
Status proyek.
ACTIVEberarti proyek siap digunakan.ARCHIVEDberarti proyek telah diarsipkan dan tidak dapat menerima permintaan inferensi baru. - CreatedAt
-
Stempel waktu di mana proyek itu dibuat.
- UpdatedAt
-
Stempel waktu di mana proyek terakhir diperbarui.
Contoh
Buat Proyek Dasar
Contoh berikut membuat proyek untuk aplikasi chatbot produksi:
contoh Proyek Dasar
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"] } } } }
Buat Beberapa Proyek untuk Lingkungan yang Berbeda
Contoh berikut menyediakan proyek terpisah untuk pengembangan, pementasan, dan lingkungan produksi dalam satu tumpukan:
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"
Membuat Proyek dengan Akses Peran IAM
Contoh berikut membuat proyek dan melampirkan kebijakan IAM yang memberikan akses peran tertentu ke model pemanggilan:
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
Menggunakan CloudFormation Output dengan API Proyek
Setelah menerapkan CloudFormation tumpukan Anda, Anda dapat mereferensikan ARN dan ID proyek dalam kode aplikasi Anda menggunakan output tumpukan:
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)
Pelajari Lebih Lanjut
Untuk informasi selengkapnya tentang penggunaan CloudFormation dengan sumber daya Amazon Bedrock, lihat: