Đây là kiểm tra an toàn hơn bởi vì tôi đã giải quyết được vấn đề nhưng tôi không thuyết phục tôi đã thực hiện nó một cách thông minh.AWS - Giả sử IAM sử dụng PowerShell trên một cá thể
Vấn đề
Tôi có một số trường hợp đã được giao một vai trò IAM cho phép họ truy cập vào một xô S3. Sau đó, tôi cần chạy một số tập lệnh PowerShell sẽ truy cập vào thùng S3 để tải xuống một số đối tượng.
Giải pháp
Để có được/thiết lập các thông tin quan trọng để sử dụng tôi đã viết chức năng PowerShell này:
function Set-MyInstanceProfileCredentials {
param(
[parameter()]
[string]
$StoredCredentialsName = "MyInstanceProfileCredentials"
)
$Uri = "http://169.254.169.254/latest/meta-data/iam/security-credentials/"
Write-Verbose "Retrieving instance profile from $($Uri)"
$Uri = "$Uri$(Invoke-RestMethod -Uri $Uri)"
Write-Verbose "Retrieving security credentials from $($Uri)"
$Response = Invoke-RestMethod -Uri $Uri
Set-AWSCredentials -AccessKey $Response.AccessKey -SecretKey $Response.SecretAccessKey -StoreAs $StoredCredentialsName
Get-AWSCredentials -StoredCredentials $StoredCredentialsName
}
Sau đó, khi tôi cần phải chạy một lệnh PowerShell từ các module AWS Tôi chỉ gọi hàm này trước.
Tuy nhiên tôi không thể lắc cảm giác rằng tôi đã bỏ lỡ một thứ gì đó từ mô-đun AWS PowerShell đã và đang xử lý việc này cho tôi.