Using the AWS PHP SDK to get a current EC2 node from a group of nodes
26 Jan 2018 - Aaron Dodd
When porting a Drupal application from on-site to cloud hosting, one of the issues was the use of drush aliases in one environment for drush commands to be run against the cloud environment. Since EC2 nodes in an autoscaling group can be replaced at any time, the developers needed an alternative to hard-coding IPs.
Below is a snippet of a drushrc file. Assuming the aws.phar is in the same folder as the drushrc, and the AWS CLI is properly configured with credentials (or, if this is on an EC2 instance, an IAM role is applied), this will query for nodes matching a tag “Group” and return the list. The drush aliases are then set to reference only the first response for the query.
Multiple filters can be applied in the query, just be sure to create a second array under Filters.