title: Public key creation in AWS cloudformation giving following error: Invalid request provided: AWS::CloudFront::PublicKey
body: <p>I have the following Cloudformation template (.yml file) where I am creating Public key to add to a Keygroup, also created in same template. (The public key below is just for example purpose.)</p>
  <pre><code>AWSTemplateFormatVersion: &quot;2010-09-09&quot;
  Resources:
    CloudfrontPublicKey:
      Type: AWS::CloudFront::PublicKey
      Properties:
        PublicKeyConfig:
          CallerReference: 'some-caller-reference'
          Comment: 'Public key for signed url'
          Name: 'cloudfront-public-key'
          EncodedKey: '-----BEGIN PUBLIC KEY-----aaaabbbb-----END PUBLIC KEY-----'
    CloudFrontKeyGroup:
      Type: AWS::CloudFront::KeyGroup
      Properties:
        KeyGroupConfig:
          Comment: 'Key group for signed url'
          Items:
            - !Ref CloudfrontPublicKey
          Name: 'cloudfront-key-group'
  </code></pre>
  <p>However, I am getting the following error relating to the public key</p>
  <pre><code>  Invalid request provided: AWS::CloudFront::PublicKey
  </code></pre>
  <p>The original public key is multi-line, for example:</p>
  <pre><code>-----BEGIN PUBLIC KEY-----
  aaaa
  bbbb
  -----END PUBLIC KEY-----
  </code></pre>
  <p>I tried to make it fit in single line by adding new line character as follows</p>
  <pre><code>-----BEGIN PUBLIC KEY-----\naaaa\nbbbb\n-----END PUBLIC KEY-----
  </code></pre>
  <p>I also tried without the new line character</p>
  <pre><code>-----BEGIN PUBLIC KEY-----aaaabbbb-----END PUBLIC KEY-----
  </code></pre>
  <p>Both attempts did not work, and I am still getting the same error.</p>