Is there a way to "ask" google to add a query string paramater to the url when crawling my website? (maybe in robots.txt?) so that when it crawls example.com, it would add something like ?iam=google . Because we use Cloudfront to serve our website, we need a way to detect search engines on the cloudfront and forward them to origin server.
There is no way to get Googlebot to add parameters. Google does not support such functionality.
Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
However, you should not being doing anything differently for Googlebot than you do for users. Google calls that practice cloaking. Google will penalize sites that treat Googlebot specially.
There should be no reason that your Cloudfront servers can't serve the same cached content to Googlebot that they serve to users.
If your pages are AJAX and you need Google to be able to access the content, you can implement the hash bang AJAX crawling scheme.
To implement it, you need to have use
#! in your URL where you would normalling use a
# sign. Then Googlebot will fetch a URL with a parameter
_escaped_fragment=everything+after+the+hash+sign. Your server needs to be configured to return the content that would be shown to the user at that point.
_escaped_fragment version of the URL:
<meta name="fragment" content="!">
See point #4 from "Transformation of the URL" in Google's documentation