This is the bash script I wrote that can create RSA
key and do the upload cloudfront public key as well as create cloudfront key group.
openssl genrsa -out cloudfront_private_key.pem 2048
openssl rsa -pubout -in cloudfront_private_key.pem -out cloudfront_public_key.pem
EncodedKey="$(cat ./cloudfront_public_key.pem)"
sed \
-e "s%TEPMLATE_ENCODED_PUBLIC_KEY%$(echo $EncodedKey)%g" \
./cloudfront_key_config.json.tmpl > ./cloudfront_key_config.json
sed -i 's/- /-\\n/ ; s/ -/\\n-/' ./cloudfront_key_config.json
CloudfrontKeyID=$(aws cloudfront create-public-key --public-key-config file://cloudfront_key_config.json --query 'PublicKey'.'Id' --output text)
echo "CloudFront public key created! now creating cloudfront key group ..."
sleep 10s
sed \
-e "s%TEMPLATE_KEY_ID%$(echo $CloudfrontKeyID)%g" \
./cloudfront_key_group_config.json.tmpl > ./cloudfront_key_group_config.json
CloudFrontKeyGroup=$(aws cloudfront create-key-group --key-group-config file://cloudfront_key_group_config.json --query 'KeyGroup'.'Id' --output text)
echo $CloudFrontKeyGroup
And the 2 tmpl files looks like below
# cat cloudfront_key_config.json.tmpl
{
"CallerReference": "cloudfront-public-key",
"Name": "CloudFront-Public-Key",
"EncodedKey": "TEPMLATE_ENCODED_PUBLIC_KEY",
"Comment": "CloudFront public key"
}
# cat cloudfront_key_group_config.json.tmpl
{
"Name": "CloudFront-key-group",
"Items": ["TEMPLATE_KEY_ID"],
"Comment": "Cloudfront key group"
}
ssh-keygen -b 2048
and it did not work either. It seems CloudFront specifically wants OpenSSL – Moderate