This is for a database (Postgre) VM, whose data is stored on a separate EBS volume. Can I make it so that the same EBS volume is mounted automatically (this is assuming that no other instance is using that EBS).
The reason for this would be that the db would have its data files available when it starts up.
to mount it you would need to add an entry in your fstab file (/etc/fstab)
something like this, although it is possible it will vary from this. you can man fstab for more information
If you do a df -T you will get all the information you need
so you know that the device is xvdf1 (it may be sdf1 or something like this) the second entry is where you want it mounted, the third entry is the filesystem type (which you can see as the second entry in the df -T command) and if you don't understand fstab, it's probably best to leave it as defaults and 0 0
Hope this helps.
When you attach a volume to an EC2 instance, it will remain attached to that instance until it is explicitly detached. Even when the instance is stopped, the volume will remain attached. It will have a constant device name such as /dev/sdf1.
When using a Linux instance, you can add a line to /etc/fstab to have the volume mounted into your filesystem on boot.
Presumably you are wondering how to automatically attach the volume from an Amazon EC2 API level perspective (in contrast to how to mount it afterwards, which is a secondary OS level perspective)?
The answer to this is simple, the CreateImage API (used in the AWS Management Console or the ec2-create-image command line tool in turn) automatically takes care of this:
There is a caveat to beware of, insofar the AMI creation process excludes stuff that is considered temporary from an OS level perspective - I haven't been able to find the official reference for this, but Nishant's answer to the related question Can I create an AMI that includes multiple ebs volumes (i.e. both sda and sdb) lists these correctly, as far as I recall:
Might be better would be to create volume from snapshot during boot instead of attaching specific volume. This is more flexible - you could launch your instance in another availability zone and you won't get conflicts with existing instance. Also with new Snapshot Copy feature - http://aws.amazon.com/about-aws/whats-new/2012/12/17/announcing-ebs-snapshot-copy/ - you could copy snapshot and launch instance even in another AWS region. And finally by doing snapshot you will do backups of your data which is must-have in the cloud...