How to auto-provision AMI gateway on Amazon

Document ID : KB000071459
Last Modified Date : 12/07/2018
Show Technical Document Details
Introduction:
APIM gateway supports headless configuration and Amazon AMI supports cloud-init script, but running headless configuration in cloud-init as per the product document will fail because the documentation assumes the gateway is up and running. When the cloud-init script is executed during the initialization of the AMI instance, the gateway and mysql are not yet started so it will fail.

Need to ensure the gateway is running before start headless config.
Instructions:
When EC2 instance is launched via the gateway AMI  a user-data script can be input in the Instance Details, Advanced Options section.
Here is an example of a user-data script (which connects to mysql locally) to start the mysql and gateway first.

#!/bin/bash
service mysql start
service ssg start
sleep 2m
echo configure.db=true > create-node.properties
echo database.type=mysql >> create-node.properties
echo database.host=localhost >> create-node.properties
echo database.port=3306 >> create-node.properties
echo database.name=ssg >> create-node.properties
echo database.user=gateway >> create-node.properties
echo database.pass=7layer >> create-node.properties
echo database.admin.user=root >> create-node.properties
echo database.admin.pass=7layer  >> create-node.properties
echo node.enable=true >> create-node.properties
echo configure.node=true >> create-node.properties
echo admin.user=admin >> create-node.properties
echo admin.pass=7layer >> create-node.properties
echo cluster.host=`hostname` >> create-node.properties 
echo cluster.pass=7layer >> create-node.properties
cat create-node.properties | /opt/SecureSpan/Gateway/config/bin/ssgconfig-headless create
# end of script

The /var/log/cloud-init-output.log shows following,
Cloud-init v. 0.7.5 running 'modules:config' at Mon, 05 Feb 2018 23:17:45 +0000. Up 652.75 seconds.
Cloud-init v. 0.7.5 running 'modules:final' at Mon, 05 Feb 2018 23:17:52 +0000. Up 659.44 seconds.
Starting MySQL............. SUCCESS!
Starting Gateway Services: [  OK  ]
Configuration Successful
Additional Information:

Auto-Provision a Gateway Node