1

我試圖部署一個Auto Scaling組,其所有EC2實例都自動連接到AWS指令服務。我跟着本教程中的所有步驟:https://aws.amazon.com/blogs/security/how-to-configure-your-ec2-instances-to-automatically-join-a-microsoft-active-directory-domain/無法使用Auto Scaling Group將EC2實例關聯到Active Directory

這是我使用的用戶數據腳本(其將代碼安裝部署也)

<powershell> 
New-Item -Path c:\temp -ItemType "directory" -Force 
Read-S3Object -BucketName aws-codedeploy-us-east-1/latest -Key codedeploy-agent.msi -File c:\temp\codedeploy-agent.msi 
Start-Process -Wait -FilePath c:\temp\codedeploy-agent.msi -WindowStyle Hidden 

Set-Variable -name instance_id -value (Invoke-Restmethod -uri http://169.254.169.254/latest/meta-data/instance-id) 
New-SSMAssociation -InstanceId $instance_id -Name "ssmDocumentName_works_fine" 
</powershell> 

我使用的是自定義的AMI。在創建AMI之前,我啓動了EC2ConfigService設置,並選中了以下選項:啓用用戶數據執行以啓動下次服務。

但是,當新的實例由ASG啓動時,它不是任何域的一部分。它仍然在工作組中:WORKGROUP。如果我將RDP添加到EC2並在PowerShell中運行用戶數據,則會出現「AssociationAlreadyExistsException」異常。

爲什麼EC2沒有連接到活動目錄?

謝謝

回答