json構文で二重引用符を含むAWS CLIコマンドを渡すことはできません。

json構文で二重引用符を含むAWS CLIコマンドを渡すことはできません。

以下のスクリプトを使用していますが、Secret Managerで資格情報を取得できないため、構文エラーが発生します。 「ユーザー名」:「入力したアクセスキーのAWS CLIコマンド」、「パスワード」:「入力したキーのAWS CLIコマンド」。誰かが助けることができれば良いでしょう。

#!/bin/bash

# Send the POST request and capture the response
response=$(curl -k \
-H "Content-Type: application/json" \
-X POST \
-d \
'{
"username":"'aws secretsmanager get-secret-value --region ap-south-1 --secret-id poc | jq --raw-output '.SecretString' | jq -r '.Access_Key''",
"password":"'aws secretsmanager get-secret-value --region ap-south-1 --secret-id poc | jq --raw-output '.SecretString' | jq -r '.Secret_Key''"
}' \
https://<region>/api/v1/authenticate)

ベストアンサー1

どうすればいいですか?シェルを使うここに文書があります:

#!/bin/bash

username=$(aws secretsmanager get-secret-value ... | jq '...')
password=$(aws secretsmanager get-secret-value ... | jq '...')
anotherVariable=foobar

# Send the POST request and capture the response
response=$(
    curl -k \
        -H "Content-Type: application/json" \
        https://<region>/api/v1/authenticate
        -d @/dev/stdin <<EOF
        {
            "username": $username,
            "password": $password,
            "anotherKey": "$anotherVariable"

        }
EOF
)

-X POST使用には必要ありません-d


慣れたら、jq@Kusalanandaの回答を選択または混合してみてください。そうでなければ、慣れていない場合jq

おすすめ記事