To copy Heap Dump from EC2 instance in AWS can be done using jmap command. To do so log into the instance as super user by executing the below command using Cygwin terminal:-
sudo su - username [sam@student-server-111hared-i-074173501c09d2a88 ~]$$ jcmd
The above command displays the process Id 3695 of our server component running in EC2.
3695 /opt/vgt/projectname-server-deployable/1668/runtime/jar/application/projectname-server-app-1668.war
Now by executing jmap command we will take the heap dump.
jmap utility is used for printing memory statistics for a running instance. The dump file is taken in binary HPROF format as seen below:-
jmap -dump:live,format=b,file=/tmp/projectname_heapdump.hprof 3695
chmod 755 /tmp/idp_heapdump.hprof // Set the permission in case of access denied
scp 172.27.210.166:/tmp/idp_heapdump.hprof . // Copies the heap dump to local /Cygwin/home/username/ directory
This file can be read using jhat tool or other heap dump viewing tools.