

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
<a name="cloudformation-projects"></a>

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
<a name="cloudformation-projects-resource"></a>

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
<a name="cloudformation-projects-syntax"></a>

Untuk mendeklarasikan entitas ini di CloudFormation template Anda, gunakan sintaks berikut:

**Example 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
<a name="cloudformation-projects-properties"></a>

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
<a name="cloudformation-projects-return-values"></a>

#### Ref
<a name="cloudformation-projects-ref"></a>

Ketika Anda meneruskan ID logis dari sumber daya ini ke `Ref` fungsi intrinsik, `Ref` mengembalikan ID proyek (misalnya,`proj_abc123`).

#### Fn:: GetAtt
<a name="cloudformation-projects-getatt"></a>

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. `ACTIVE`berarti proyek siap digunakan. `ARCHIVED`berarti 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
<a name="cloudformation-projects-examples"></a>

### Buat Proyek Dasar
<a name="cloudformation-projects-basic"></a>

Contoh berikut membuat proyek untuk aplikasi chatbot produksi:

**Example 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
<a name="cloudformation-projects-multi-env"></a>

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
<a name="cloudformation-projects-iam"></a>

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
<a name="cloudformation-projects-using-outputs"></a>

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
<a name="cloudformation-projects-learn-more"></a>

Untuk informasi selengkapnya tentang penggunaan CloudFormation dengan sumber daya Amazon Bedrock, lihat:
+ [Buat sumber daya Amazon Bedrock dengan AWS CloudFormation](creating-resources-with-cloudformation.md)
+ [Panduan CloudFormation Pengguna AWS](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html)
+ [Referensi jenis sumber daya Amazon Bedrock](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/AWS_Bedrock.html)