How to publish your Liferay based product in the AWS marketplace

What is AWS Marketplace?

AWS Marketplace is an online store where you can sell or buy software that runs on Amazon Web Services. These are pre-configured system images, which can be executed by customers on their selected server configuration with just a few clicks. Putting your product there will allow your customers to use it without going through the trouble of installation and configuration.
Using this marketplace is essentially free for everyone, only an AWS account is needed both buyer and seller side. Of course, Amazon's server resources are not always free, and your application will run on that.
 

What is this article about?

I'll assume that you already have a product that you would like to publish, and you know how to set it up on a distant server. I'll show you how to create an image from it and how publish it on the AWS marketplace.
 
Your product has to be self-contained. It can use outside systems, but it cannot depend on them. For example, your Liferay's database has to be included.

 

1. Foundations

I suggest you to build up your product on one of the pre-made OS images from Amazon. There is a possibility to import your own image, but you can save a lot of trouble for yourself if you start with something that has been already verified by Amazon.
 

1.1. Register

If you don't have an account register nowYou will need a valid credit card and a phone.
 

1.2. Launch your system

On the AWS, you can store and run your instances in several locations You can change your current location in the Main Menu, on the top-right corner. However, in the Marketplace, you can only use images stored in US East (N. Virginia).
  • Go to Main Menu → Compute → EC2 and click on the Launch Instance button.
  • Select your desired operation system.
  • Select a big enough instance type. These instances are hourly priced, so even if you select a very fast one, it won't cost you much within a few hours. Don't forget to shut it down when you've finished!
  • On the Tag Instance tab, name your instance.
  • On the Configure Security Group, add a custom TCP rule for the port 8080. You will need that for Liferay.
  • Before launch, you will be asked to create a keypair. Download and store it well.
 
I have chosen Ubuntu Server 14.04, so the following example codes will be for that.
 

1.3. Connect to your system

Go to Main menu → Compute → EC2 → Instances to see your running instance. Right Click → Connect and you will see detailed information about how to connect to it through SSH.
 

2. Build your product

I will leave these steps to you. You have SSH access to the server. Build up and configure your Liferay based product there. If you need more access, you can manage it in Main menu → Compute → EC2 → Security Groups.

 

3. Things to look out for

3.1. Tomcat auto start

Your tomcat server should start up and shut down automatically when the server does. If you didn't do that already, use the following script as an example.
 
Don't forget to:
  • Specify your own JAVA_HOME in line 7.
  • Specify your own CATALINA_HOME in line 10.
  • Specify your own username in line 17 and 24.
  • Save the script to /etc/init.d/tomcat
Save it into your /etc/init.d/ folder under the name of tomcat and configure your Ubuntu to run it automatically.
$sudo ln -s /etc/init.d/tomcat /etc/rc1.d/K99tomcat
$sudo ln -s /etc/init.d/tomcat /etc/rc2.d/S99tomcat
 

3.2. Liferay passwords

The user-interface, that is Liferay in our case, cannot have default passwords. They have to be generated based on unique data supplied by Amazon to the instance. It makes sense, because this way if someone launches your image, you won't know their passwords.  This criteria is not checked by Amazon's automated tests, but they check it manually and reject you anyway.
 
My suggestion is to write a script that reads out the instance ID from the instance metadata and sets it as a password for every liferay user on the first start-up. Detailed information about the instance metadata can be found here.
 
The instance id can be read out with the following command:
$curl http://169.254.169.254/latest/meta-data/instance-id
I give you my scripts as an example. I've used PostgreSQL 9.3 on Ubuntu 14.04.
 

Don't forget to run the main script on start-up, similarly to the previous tomcat script. Just change the IDs from 99 to 98.

3.3. Check the seller's guide

After the next step, you won't be able to modify this instance directly, so this would be a good time to don't trust me and check the seller's guide by yourself. If step 4.2 or 4.3 fails, you can still return to here.
 

3.4. Shut the doors

As a last step, you should lock yourself out of your instance completely. 
  • Disable the password authentication through SSH and erase the passwords for every user. If you have built upon an image from Amazon, you don't have to worry about this, it has been done already.
  • Delete every saved public key. On Ubuntu, they are in /home/userName/.ssh/authorized_keys. Delete that file. Also delete the one for the root user in /root/.ssh/
Yes, you will never be able to connect this instance, and that is the point. When somebody runs the AMI image, Amazon will inject the needed public keys during the launch procedure. You won't have access to it, only the person who runs it.
 

4. Create and Validate your AMI image

4.1. Create your image

  • Shut down your instance. In the instances window, Right Click -> Instance State -> Stop
  • Right Click -> Create Image. There you have to specify name, description and instance volumes. These won't be displayed in the marketplace, they are just for you.

4.2. Validate and publish your image

  • Go to the following page and select the "AMIs" tab. You will see your AMIs on the US East (N. Virginia) server.
  • Select the one you've created and specify its username (on our Ubuntu server, it was "ubuntu").
  • Click on the "Share AMIs" Button. This will trigger Amazon's automated tests.
The tests will take around an hour and if you have skipped step 3.3 or if you didn't give the correct username, they will fail. In that case, go to step 5. The results will provide detailed information about what you have to do.
 

4.3. Submit your image

If you see a nice green Successfull text in the Status column under the AMIs -> Shared tab, you can continue and submit your AMI to the marketplace. Download this xlsx form, and fill it. It has very detailed instructions how to do it.  Upload your filled form here .
 
They will contact you within one day. If you have skipped step 3.2 or they find other problems, they will reject you and tell you what is wrong. Otherwise, they will upload your AMI to the marketplace in private mode and send you a link to it. At this point, only you can see and access it. If you are satisfied with the result, ask them to make it public and very soon everybody can see your product.
 

5. Updating and fixing errors

If you have to fix something or update your product, go to Main menu → Compute → EC2 → Images -> AMIs, launch your image and continue the process from step 1.3.