Skip to content

Instantly share code, notes, and snippets.

@stknohg
Created April 10, 2024 01:53
Show Gist options
  • Save stknohg/36d1f97107df5de6c56a083c65b069c4 to your computer and use it in GitHub Desktop.
Save stknohg/36d1f97107df5de6c56a083c65b069c4 to your computer and use it in GitHub Desktop.
一瞬だけクレデンシャルを拝借させていただくコマンドたち

こちらの記事のコマンドの他シェル、~/.aws/credentials 用コマンド。

Bash等 (元記事のコマンド)

元記事のコマンドはこちら。

# 環境変数 : Bash
curl -s -H "X-aws-ec2-metadata-token: $AWS_CONTAINER_AUTHORIZATION_TOKEN" $AWS_CONTAINER_CREDENTIALS_FULL_URI \
    | jq -r "[\"export AWS_ACCESS_KEY_ID=\" + .AccessKeyId, \"export AWS_SECRET_ACCESS_KEY=\" + .SecretAccessKey,\"export AWS_SESSION_TOKEN=\" + .Token] | .[]"

PowerShell

# 環境変数 : PowerShell
curl -s -H "X-aws-ec2-metadata-token: $AWS_CONTAINER_AUTHORIZATION_TOKEN" $AWS_CONTAINER_CREDENTIALS_FULL_URI \
    | jq -r "[\"\$env:AWS_ACCESS_KEY_ID='\" + .AccessKeyId + \"'\", \"\$env:AWS_SECRET_ACCESS_KEY='\" + .SecretAccessKey + \"'\", \"\$env:AWS_SESSION_TOKEN='\" + .Token  + \"'\"] | .[]"

Nushell

Nushell 0.92.1で動作確認しています。
=を付けるときは必ずスペースを空ける必要があります。

# 環境変数 : Nushell
curl -s -H "X-aws-ec2-metadata-token: $AWS_CONTAINER_AUTHORIZATION_TOKEN" $AWS_CONTAINER_CREDENTIALS_FULL_URI \
    | jq -r "[\"\$env.AWS_ACCESS_KEY_ID = '\" + .AccessKeyId + \"'\", \"\$env.AWS_SECRET_ACCESS_KEY = '\" + .SecretAccessKey + \"'\", \"\$env.AWS_SESSION_TOKEN = '\" + .Token  + \"'\"] | .[]"

~/.aws/credentials

一時的なプロファイルを用意する必要がある時に。

# ~/.aws/credentials
curl -s -H "X-aws-ec2-metadata-token: $AWS_CONTAINER_AUTHORIZATION_TOKEN" $AWS_CONTAINER_CREDENTIALS_FULL_URI \
    | jq -r "[\"aws_access_key_id=\" + .AccessKeyId, \"aws_secret_access_key=\" + .SecretAccessKey,\"aws_session_token=\" + .Token] | .[]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment