Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.
Memulai dengan AWS DevOps Agen menggunakan AWS CloudFormation
Gambaran umum
Panduan ini menunjukkan cara menggunakan AWS CloudFormation templat untuk membuat dan menyebarkan sumber daya AWS DevOps Agen. Template mengotomatiskan pembuatan ruang agen, peran AWS Identitas dan Manajemen Akses (IAM), aplikasi operator, dan asosiasi AWS akun sebagai infrastruktur sebagai kode.
Pen CloudFormation dekatan ini mengotomatiskan langkah-langkah manual yang dijelaskan dalam panduan orientasi CLI dengan mendefinisikan semua sumber daya yang diperlukan dalam templat YAML deklaratif.
AWS DevOps Agen tersedia di beberapa Wil AWS ayah. Untuk daftar lengkapnya, lihat Wilayah yang Didukung.
Prasyarat
Sebelum Anda mulai, pastikan Anda memiliki yang berikut:
AWS Command Line Interface (AWS CLI) diinstal dan dikonfigurasi dengan kredenSIAL yang sesuai
Izin untuk membuat peran dan CloudFormation tumpukan IAM
Satu AWS akun untuk akun pemantauan (primer)
(Opsional) AWS Akun kedua jika Anda ingin mengatur pemantauan lintas akun
Apa yang dicakup panduan ini
Panduan ini dibagi menjadi beberapa bagian berikut:
Bagian 1 - Menyebarkan ruang agen dengan aplikasi operator dan asosi AWS asi di akun pemantauan Anda. Setelah Anda menyelesaikan bagian ini, agen dapat memantau masalah di akun tersebut.
Bagian 2 (Opsional) — Menyebarkan peran IAM lintas akun ke akun sekunder dan tambahkan asosiasi sumber AWS . Konfigurasi ini memungkinkan ruang agen untuk memantau sumber daya di seluruh akun.
Bagian 3 (Opsional) — Tambahkan keterampilan, agen khusus, dan pemicu terjadwal ke ruang agen, sehingga agen memiliki pengetahuan khusus dan menjalankan agen khusus sesuai jadwal.
Bagian 1: Menyebarkan ruang agen
Di bagian ini, Anda membuat CloudFormation template yang menyediakan ruang agen, peran IAM, aplikasi operator, dan as AWS osiasi di akun pemantauan Anda.
Langkah 1: Buat CloudFormation template
Simpan template berikut sebagaidevops-agent-stack.yaml:
AWSTemplateFormatVersion: '2010-09-09' Description: AWS DevOps Agent - Agent Space with IAM roles, operator app, and AWS association Parameters: AgentSpaceName: Type: String Default: MyCloudFormationAgentSpace Description: Name for the agent space AgentSpaceDescription: Type: String Default: Agent space deployed with CloudFormation Description: Description for the agent space Resources: # IAM role assumed by the DevOps Agent service to monitor the account DevOpsAgentSpaceRole: Type: AWS::IAM::Role Properties: RoleName: DevOpsAgentRole-AgentSpace AssumeRolePolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Principal: Service: aidevops.amazonaws.com Action: sts:AssumeRole Condition: StringEquals: aws:SourceAccount: !Ref AWS::AccountId ArnLike: aws:SourceArn: !Sub arn:aws:aidevops:${AWS::Region}:${AWS::AccountId}:agentspace/* ManagedPolicyArns: - arn:aws:iam::aws:policy/AIDevOpsAgentAccessPolicy Policies: - PolicyName: AllowCreateServiceLinkedRoles PolicyDocument: Version: '2012-10-17' Statement: - Sid: AllowCreateServiceLinkedRoles Effect: Allow Action: - iam:CreateServiceLinkedRole Resource: - !Sub arn:aws:iam::${AWS::AccountId}:role/aws-service-role/resource-explorer-2.amazonaws.com/AWSServiceRoleForResourceExplorer # IAM role for the operator app interface DevOpsOperatorRole: Type: AWS::IAM::Role Properties: RoleName: DevOpsAgentRole-WebappAdmin AssumeRolePolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Principal: Service: aidevops.amazonaws.com Action: - sts:AssumeRole - sts:TagSession Condition: StringEquals: aws:SourceAccount: !Ref AWS::AccountId ArnLike: aws:SourceArn: !Sub arn:aws:aidevops:${AWS::Region}:${AWS::AccountId}:agentspace/* ManagedPolicyArns: - arn:aws:iam::aws:policy/AIDevOpsOperatorAppAccessPolicy # The agent space resource AgentSpace: Type: AWS::DevOpsAgent::AgentSpace DependsOn: - DevOpsAgentSpaceRole - DevOpsOperatorRole Properties: Name: !Ref AgentSpaceName Description: !Ref AgentSpaceDescription OperatorApp: Iam: OperatorAppRoleArn: !GetAtt DevOpsOperatorRole.Arn # Association linking the monitoring account to the agent space MonitorAssociation: Type: AWS::DevOpsAgent::Association Properties: AgentSpaceId: !GetAtt AgentSpace.AgentSpaceId ServiceId: aws Configuration: Aws: AssumableRoleArn: !GetAtt DevOpsAgentSpaceRole.Arn AccountId: !Ref AWS::AccountId AccountType: monitor Outputs: AgentSpaceId: Description: The agent space ID Value: !GetAtt AgentSpace.AgentSpaceId AgentSpaceArn: Description: The agent space ARN Value: !GetAtt AgentSpace.Arn AgentSpaceRoleArn: Description: The agent space IAM role ARN Value: !GetAtt DevOpsAgentSpaceRole.Arn OperatorRoleArn: Description: The operator app IAM role ARN Value: !GetAtt DevOpsOperatorRole.Arn
Langkah 2: Terapkan tumpukan
Jalankan perintah berikut untuk menyebarkan tumpukan. Ganti <REGION> dengan Wilayah yang Didukung (misalnya,us-east-1).
aws cloudformation deploy \ --template-file devops-agent-stack.yaml \ --stack-name DevOpsAgentStack \ --capabilities CAPABILITY_NAMED_IAM \ --region <REGION>
Langkah 3: Rekam output tumpukan
Setelah penerapan selesai, jalankan perintah berikut untuk mengambil output tumpukan. Catat nilai-nilai ini untuk digunakan nanti.
aws cloudformation describe-stacks \ --stack-name DevOpsAgentStack \ --query 'Stacks[0].Outputs' \ --region <REGION>
Contoh berikut menunjukkan output yang diharapkan:
[ { "OutputKey": "AgentSpaceId", "OutputValue": "abc123def456" }, { "OutputKey": "AgentSpaceArn", "OutputValue": "arn:aws:aidevops:<REGION>:<ACCOUNT_ID>:agentspace/abc123def456" }, { "OutputKey": "AgentSpaceRoleArn", "OutputValue": "arn:aws:iam::<ACCOUNT_ID>:role/DevOpsAgentRole-AgentSpace" }, { "OutputKey": "OperatorRoleArn", "OutputValue": "arn:aws:iam::<ACCOUNT_ID>:role/DevOpsAgentRole-WebappAdmin" } ]
Jika Anda berencana untuk menyelesaikan Bagian 2, simpan nil AgentSpaceArn ainya. Anda membutuhkannya untuk mengonfigurasi peran lintas akun.
Langkah 4: Verifikasi penerapan
Untuk memverifikasi bahwa ruang agen berhasil dibuat, jalankan perintah AWS CLI berikut:
aws devops-agent get-agent-space \ --agent-space-id <AGENT_SPACE_ID> \ --region <REGION>
Pada titik ini, ruang agen Anda digunakan dengan aplikasi operator diaktifkan dan akun pemantauan Anda terkait. Agen dapat memantau masalah di akun ini.
Bagian 2 (Opsional): Tambahkan pemantauan lintas akun
Di bagian ini, Anda memperluas pengaturan sehingga ruang agen Anda dapat memantau sumber daya di AWS akun kedua (akun layanan). Ini melibatkan dua tindakan:
Menyebarkan peran IAM di akun layanan yang mempercayai ruang agen.
Menambahkan as AWS osiasi sumber di akun pemantauan yang menunjuk ke akun layanan.
Anda harus menyelesaikan Bagian 1 sebelum melanjutkan. Template akun layanan memerlukan output tumpukan AgentSpaceArn dari Bagian 1.
Langkah 1: Buat template akun layanan
Simpan template berikut sebagaidevops-agent-service-account.yaml. Template ini membuat peran IAM lintas akun di akun sekunder.
AWSTemplateFormatVersion: '2010-09-09' Description: AWS DevOps Agent - Cross-account IAM role for secondary account monitoring Parameters: MonitoringAccountId: Type: String Description: The 12-digit AWS account ID of the monitoring account AgentSpaceArn: Type: String Description: The ARN of the agent space from the monitoring account Resources: # Cross-account IAM role trusted by the agent space DevOpsSecondaryAccountRole: Type: AWS::IAM::Role Properties: RoleName: DevOpsAgentRole-SecondaryAccount AssumeRolePolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Principal: Service: aidevops.amazonaws.com Action: sts:AssumeRole Condition: StringEquals: aws:SourceAccount: !Ref MonitoringAccountId ArnLike: aws:SourceArn: !Ref AgentSpaceArn ManagedPolicyArns: - arn:aws:iam::aws:policy/AIDevOpsAgentAccessPolicy Policies: - PolicyName: AllowCreateServiceLinkedRoles PolicyDocument: Version: '2012-10-17' Statement: - Sid: AllowCreateServiceLinkedRoles Effect: Allow Action: - iam:CreateServiceLinkedRole Resource: - !Sub arn:aws:iam::${AWS::AccountId}:role/aws-service-role/resource-explorer-2.amazonaws.com/AWSServiceRoleForResourceExplorer Outputs: SecondaryAccountRoleArn: Description: The cross-account IAM role ARN Value: !GetAtt DevOpsSecondaryAccountRole.Arn
Langkah 2: Menyebarkan tumpukan akun layanan
Menggunakan kredenSIAL untuk akun layanan, jalankan perintah berikut:
aws cloudformation deploy \ --template-file devops-agent-service-account.yaml \ --stack-name DevOpsAgentServiceAccountStack \ --capabilities CAPABILITY_NAMED_IAM \ --parameter-overrides \ MonitoringAccountId=<MONITORING_ACCOUNT_ID> \ AgentSpaceArn=<AGENT_SPACE_ARN> \ --region <REGION>
Langkah 3: Tambahkan sumber AWS asosiasi
Beralih kembali ke akun pemantauan dan buat as AWS osiasi sumber. Anda dapat melakukan ini dengan membuat tumpukan terpisah atau dengan memperbarui template asli. Contoh berikut menggunakan template mandiri.
Simpan template berikut sebagaidevops-agent-source-association.yaml:
AWSTemplateFormatVersion: '2010-09-09' Description: AWS DevOps Agent - Source AWS association for cross-account monitoring Parameters: AgentSpaceId: Type: String Description: The agent space ID from the monitoring account stack ServiceAccountId: Type: String Description: The 12-digit AWS account ID of the service account ServiceAccountRoleArn: Type: String Description: The ARN of the DevOpsAgentRole-SecondaryAccount role in the service account Resources: SourceAssociation: Type: AWS::DevOpsAgent::Association Properties: AgentSpaceId: !Ref AgentSpaceId ServiceId: aws Configuration: SourceAws: AccountId: !Ref ServiceAccountId AccountType: source AssumableRoleArn: !Ref ServiceAccountRoleArn Outputs: SourceAssociationId: Description: The source association ID Value: !Ref SourceAssociation
Terapkan tumpukan asosiasi menggunakan kredentif akun pemantauan:
aws cloudformation deploy \ --template-file devops-agent-source-association.yaml \ --stack-name DevOpsAgentSourceAssociationStack \ --parameter-overrides \ AgentSpaceId=<AGENT_SPACE_ID> \ ServiceAccountId=<SERVICE_ACCOUNT_ID> \ ServiceAccountRoleArn=arn:aws:iam::<SERVICE_ACCOUNT_ID>:role/DevOpsAgentRole-SecondaryAccount \ --region <REGION>
Bagian 3: Tambahkan keterampilan, agen khusus, dan pemicu terjadwal
Bagian ini opsional. Di bagian ini, Anda menambahkan tiga sumber daya ke ruang agen yang Anda buat di Bagian 1. Yang pertama adalah keterampilan yang dimuat agen ketika relevan. Yang kedua adalah agen kustom yang menjangkau agen ke alur kerja tertentu. Yang ketiga adalah pemicu ter jadwal yang menjalankan agen kustom secara otomatis. Sumber daya ini menggunakan jenis AWS::DevOpsAgent::Trigger sumber daya AWS::DevOpsAgent::Asset dan. Untuk informasi selengkapnya tentang mengelola aset sebagai infrastruktur sebagai kode, lihatMengelola aset.
Anda harus menyelesaikan Bagian 1 sebelum melanjutkan. Template ini membutuhkan output AgentSpaceId dari tumpukan Bagian 1.
Langkah 1: Buat template
Simpan template berikut sebagaidevops-agent-content.yaml. Tindakan pemicu berbasis waktu mereferensikan agen kustom berdasarkan ID aset, dalam formulircustom:<assetId>. Template menghubungkan ini secara otomatisFn::GetAtt.
AWSTemplateFormatVersion: '2010-09-09' Description: AWS DevOps Agent - Example skill, custom agent, and scheduled trigger Parameters: AgentSpaceId: Type: String Description: The agent space ID from the Part 1 stack outputs Resources: # A skill the agent loads when relevant ExampleSkill: Type: AWS::DevOpsAgent::Asset Properties: AgentSpaceId: !Ref AgentSpaceId AssetType: skill Metadata: name: rds-performance-investigation description: Investigation procedures for RDS performance issues. agent_types: - GENERIC Files: - Path: SKILL.md ContentText: | # RDS Performance Investigation Use this skill when investigating database latency, connection errors, or query timeouts. # A custom agent that a trigger can invoke ExampleCustomAgent: Type: AWS::DevOpsAgent::Asset Properties: AgentSpaceId: !Ref AgentSpaceId AssetType: custom_agent Metadata: name: rds-firefighter skills: - rds-performance-investigation Files: - Path: AGENT.md ContentText: | # RDS Firefighter Custom agent for RDS incidents. # A time-based trigger that runs the custom agent on a schedule DailyTrigger: Type: AWS::DevOpsAgent::Trigger Properties: AgentSpaceId: !Ref AgentSpaceId Type: TIME_BASED Condition: Schedule: Expression: rate(1 day) Action: actionType: create:task task: agent: !Sub - custom:${AssetId} - AssetId: !GetAtt ExampleCustomAgent.AssetId Status: Active Outputs: SkillAssetId: Description: The skill asset ID Value: !GetAtt ExampleSkill.AssetId CustomAgentAssetId: Description: The custom agent asset ID Value: !GetAtt ExampleCustomAgent.AssetId TriggerId: Description: The trigger ID Value: !GetAtt DailyTrigger.TriggerId
Langkah 2: Terapkan tumpukan
Menggunakan kredenSIAL akun pemantauan, jalankan perintah berikut. Ganti <AGENT_SPACE_ID> dengan nilai dari output Bagian 1.
aws cloudformation deploy \ --template-file devops-agent-content.yaml \ --stack-name DevOpsAgentContentStack \ --parameter-overrides AgentSpaceId=<AGENT_SPACE_ID> \ --region <REGION>
Pro AgentSpaceId pertiType,Condition,, dan Action hanya dibuat. Mengubah salah satu dari mereka menggantikan sumber daya. Anda dapat memperbarui pemicu Status (ActiveatauInactive) di tempat—mengaturnya Inactive untuk menjeda pemicu tanpa menghapusnya. Untuk informasi selengkapnya tentang jenis aset lainnya dan referensi properti lengkap, lihatMengelola aset.
Verifikasi
Verifikasi penyiapan Anda dengan menjalankan perintah AWS CLI berikut:
# List your agent spaces aws devops-agent list-agent-spaces \ --region <REGION> # Get details of a specific agent space aws devops-agent get-agent-space \ --agent-space-id <AGENT_SPACE_ID> \ --region <REGION> # List associations for an agent space aws devops-agent list-associations \ --agent-space-id <AGENT_SPACE_ID> \ --region <REGION>
Pemecahan masalah
Bagian ini menjelaskan masalah umum dan cara mengatasinya.
CloudFormation Jenis sumber daya tidak ditemukan
Verifikasi bahwa Anda menerapkan di aWilayah yang Didukung.
Konfirmasikan bahwa AWS CLI Anda dikonfigurasi dengan izin yang sesuai.
Pembuatan peran IAM gagal
Pastikan kredentif penerapan Anda memiliki izin untuk membuat peran IAM dengan nama khusus (
CAPABILITY_NAMED_IAM).Periksa apakah kondisi kebijakan kepercayaan cocok dengan ID akun Anda.
Cross-account penerapan gagal
Setiap tumpukan harus digunakan dengan kredenSIAL untuk akun target. Gunakan ben
--profiledera untuk menentukan profil AWS CLI yang benar.Verifikasi bahwa
AgentSpaceArnparameter cocok dengan ARN yang tepat dari output tumpukan Bagian 1.
Penundaan propagasi IAM
Perubahan peran IAM dapat memakan waktu beberapa menit untuk disebarkan. Jika pembuatan ruang agen gagal segera setelah pembuatan peran, tunggu beberapa menit dan gunakan kembali.
Pembersihan
Untuk menghapus semua sumber daya, hapus tumpukan dalam urutan terbalik.
Peringatan: Tindakan ini menghapus ruang agen Anda dan semua data terkait secara permanen. Tindakan ini tidak dapat dibatalkan. Pastikan Anda telah membuat cadangan informasi penting sebelum melanjutkan.
Jalankan perintah berikut untuk menghapus tumpukan:
# If you deployed the Part 3 content stack, delete it first aws cloudformation delete-stack \ --stack-name DevOpsAgentContentStack \ --region <REGION> aws cloudformation wait stack-delete-complete \ --stack-name DevOpsAgentContentStack \ --region <REGION> # If you deployed the source association stack, delete it next aws cloudformation delete-stack \ --stack-name DevOpsAgentSourceAssociationStack \ --region <REGION> aws cloudformation wait stack-delete-complete \ --stack-name DevOpsAgentSourceAssociationStack \ --region <REGION> # If you deployed the service account stack, delete it next (using service account credentials) aws cloudformation delete-stack \ --stack-name DevOpsAgentServiceAccountStack \ --region <REGION> aws cloudformation wait stack-delete-complete \ --stack-name DevOpsAgentServiceAccountStack \ --region <REGION> # Delete the main stack last aws cloudformation delete-stack \ --stack-name DevOpsAgentStack \ --region <REGION>
Langkah selanjutnya
Setelah Anda menyebarkan AWS DevOps Agen Anda dengan menggunakan AWS CloudFormation:
Untuk menghubungkan integrasi tambahan, lihatMengkonfigurasi integrasi dan pengetahuan.
Jika Anda mendaftarkan integrasi pihak ketiga, dapatkan URL webhook dan rahasianya dengan memutar webhook di konsol. AWS CloudFormation tidak mengembalikan rahasia webhook sebagai output tumpukan, karena sensitif. Untuk petunjuk tentang mengelola kredentif webhook, lihat Mengelola kreden tif webhook.
Untuk mempelajari keterampilan dan kemampuan agen, lihatDevOps Keterampilan Agen.
Untuk informasi selengkapnya tentang mengelola keterampilan, agen khusus, dan aset lainnya sebagai infrastruktur sebagai kode, lihatMengelola aset.
Untuk memahami aplikasi web operator, lihatApa itu Aplikasi Web DevOps Agen?.
Untuk referensi properti terperinci untuk jenis CloudFormation sumber daya yang digunakan dalam panduan ini, lihat Referensi jenis sumber daya AWS DevOps agen di Refer AWS CloudFormation ensi Template.