After struggling 10 hours finally I came up with a solid solution.
AWS supports config files to modify the environment. They run before deploying application. http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers.html
So I created a config file to enable gzip on IIS, placed it to ".ebextensions/gzip.config" in my project folder.
Configuration in YAML format:
container_commands:
00-server-config:
command: c:\windows\system32\inetsrv\appcmd set config /section:system.webServer/serverRuntime /frequentHitThreshold:1 /frequentHitTimePeriod:00:00:05
waitAfterCompletion: 0
01-server-config:
command: c:\windows\system32\inetsrv\appcmd set config /section:system.webServer/httpCompression /noCompressionForHttp10:False /noCompressionForProxies:False
waitAfterCompletion: 0
02-gzip-dynamic:
command: c:\windows\system32\inetsrv\appcmd set config /section:urlCompression /doDynamicCompression:True
waitAfterCompletion: 0
03_gzip_static:
command: c:\windows\system32\inetsrv\appcmd set config /section:urlCompression /doStaticCompression:True
waitAfterCompletion: 0
04_restart_iis:
command: iisreset
waitAfterCompletion: 0
There are some changes needed in web.config to system.webServer section:
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files" noCompressionForHttp10="false" noCompressionForProxies="false">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll"/>
<dynamicTypes>
<add mimeType="text/*" enabled="true"/>
<add mimeType="message/*" enabled="true"/>
<add mimeType="application/javascript" enabled="true"/>
<add mimeType="application/x-javascript" enabled="true"/>
<add mimeType="application/json; charset=utf-8" enabled="true"/>
<add mimeType="*/*" enabled="false"/>
</dynamicTypes>
<staticTypes>
<add mimeType="text/*" enabled="true"/>
<add mimeType="message/*" enabled="true"/>
<add mimeType="application/javascript" enabled="true"/>
<add mimeType="application/x-javascript" enabled="true"/>
<add mimeType="application/atom+xml" enabled="true"/>
<add mimeType="application/xaml+xml" enabled="true"/>
<add mimeType="*/*" enabled="false"/>
</staticTypes>
</httpCompression>
<httpProtocol>
<customHeaders>
<remove name="Vary" />
<add name="Vary" value="Accept-Encoding" />
</customHeaders>
</httpProtocol>
With this two changes Elastic Beanstalk instances are prepared to serve compressed static and dynamic files. Also works with CDN.