私は問題を解決したので、これはより健全なチェックですが、賢明な方法でそれを行ったとは確信していません。
問題
S3 バケットへのアクセスを許可する IAM ロールが割り当てられたインスタンスがいくつかあります。次に、その S3 バケットにアクセスしていくつかのオブジェクトをダウンロードする PowerShell スクリプトを実行する必要があります。
ソリューション
使用する資格情報を取得/設定するために、次の PowerShell 関数を作成しました。
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
}
次に、AWS モジュールから PowerShell コマンドレットを実行する必要がある場合は、最初にこの関数を呼び出します。
しかし、AWS PowerShell モジュールがすでにこれを処理してくれているので、何かを見逃しているという感覚を揺るがすことはできません。