While creating a secret using python embedding in bash, I am getting 'AWS Secret can't be converted into key names and value pairs'. Firstly wrote all in bash using aws cli command where I was also getting this error then read in one of the articles to use json.dumps function of python which also doesn't work. Any ideas. Please see code and image below.
Note:
It work with short string "hello: world", but with a long string (key and /or csr) it gives aforementioned error.
Moreover, key values are there in a plain text but not in Key/value section is what an issue is.
cat << EOF > pyscript.py #!/usr/bin/python3 -tt import json import boto3 client = boto3.client('secretsmanager') key_info = json.dumps([{"csr":"""$csr"""},{"config":"""$config"""},{"PrivateKey":"""$prvpem"""}]) response = client.create_secret( Name='marw', KmsKeyId='alias/SecretsMgr', SecretString=key_info ) print(response) EOF chmod 770 pyscript.py ./pyscript.py printf "This is BASH again\n"
Tried AWS cli as given below with the same issue. Key pairs are entered in plaintext but not in key/value section
export prvpem=`cat ${keyfile}`
export csr=`cat ${csrfile}`
export config=`cat ${key_algorithm}-$line.cfn`
# echo -e "${BLU}${prvpem}${WHT}"
aws secretsmanager create-secret --name marwahas51 \
--description "Values for this environments wildcard certifcate in ACM" \
--secret-string "{\"Privatekey\":\"$prvpem\",\"csr\":\"$csr\",\"config\":\"$config\"}" \
--kms-key-id "alias/SecretsMgr" \
--tags "Key=Environment,Value=Dev"
Edit: Scenario 1 When string is --secret-string '{"Privatekey": "$prvpem"}' Output is:
Scenario 2
When string is
--secret-string "{\"Privatekey\":\"$prvpem\"}" \
Output is: