The S3 bucket approach doesn't work if you need the SSH key for your OpsWorks cookbooks repository or application deployment.

Another solution is you can add a parameter of type `CommaDelimitedList`

for the SSH key with newlines replaced by commas, then use `Fn::Join`

to put the lines of the key back together again where you need it.

Example CloudFormation template:

```
{
"Parameters": {
"CookbooksDeployKey": {
"Type": "CommaDelimitedList",
"Description": "Enter the deploy key as CSV (replace newlines with commas)",
"NoEcho": true
}
},
"Resources": {
"myStack": {
"Type": "AWS::OpsWorks::Stack",
"Properties": {
"CustomCookbooksSource": {
"Type": "git",
"Url": "git@github.com:user/repository.git",
"Revision": "master",
"SshKey": {"Fn::Join": ["\n", {"Ref": "CookbooksDeployKey"}]}
}
}
}
}
}
```

To generate the single-line "CSV" formatted version of a private key file, the following sed command can be used (this simply replaces all newlines in the file with commas, and returns the result on stdout):

```
sed ':a;N;$!ba;s/\n/,/g' /home/user/.ssh/id_rsa
```

The result looks something like:

```
-----BEGIN RSA PRIVATE KEY-----,XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX,XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX,XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX,XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX,XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX,XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX,XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX,XXXXXXXXXXXXXXXXXXXXXXXX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