LoginSignup
0
0

More than 1 year has passed since last update.

AWS 「An error occurred (UnauthorizedOperation)」 の後に続くエラーメッセージをデコードする

Last updated at Posted at 2021-07-04

エンコードされたメッセージ

AWS CLI を利用してリソースの操作を行いたいとき、権限がなく以下のようなエンコードされたメッセージが表示される場合があります。

An error occurred (UnauthorizedOperation) when calling the StartInstances operation: You are not authorized to perform this operation. Encoded authorization failure message:AVb2wicCYlRgF_-ClFpJI0Frlc...

デコードする

以下のようにデコードし、読みやすく整形できます。

$ aws sts decode-authorization-message --encoded-message AVb2wicCYlRgF_-ClFpJI0Frlc... \ 
| sed -e 's/"{/{/g' -e 's/}"/}/g' -e 's/\\//g' | jq .

{
  "DecodedMessage": {
    "allowed": false,
    "explicitDeny": false,
    "matchedStatements": {
      "items": []
    },
    "failures": {
      "items": []
    },
    "context": {
      "principal": {
        "id": "XXXXXXXXXXXXX:i-yyyyyyyyyyyyy",
        "arn": "arn:aws:sts::123456789012:assumed-role/MyEC2ROLE/i-yyyyyyyyyyyyy"
      },
      "action": "ec2:StartInstances",
      "resource": "arn:aws:ec2:ap-northeast-1:123456789012:instance/i-zzzzzzzzzzzzz",
      "conditions": {
        "items": [
          {
            "key": "ec2:InstanceMarketType",
            "values": {
              "items": [
                {
                  "value": "on-demand"
                }
              ]
            }
          },
          {
            "key": "aws:Resource",
            "values": {
              "items": [
                {
                  "value": "instance/i-zzzzzzzzzzzzz"
                }
              ]
            }
          },
...
...
...

エンコードされたメッセージをファイルに出力し、以下のように実行することも可能です。

aws sts decode-authorization-message --encoded-message  file://error_message.txt \ 
| sed -e 's/"{/{/g' -e 's/}"/}/g' -e 's/\\//g' | jq .

今回の動作検証は Linux2 インスタンスで行いました。jq コマンドのインストールは以下の記事を参考にさせて頂きました。

参考記事

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0