/** {@inheritDoc} */
public void setInstanceSecurityGroups(String instanceId, List<String> groupIds) {
Validate.notEmpty(instanceId);
LOGGER.info(String.format("Removing all security groups from instance %s in region %s.", instanceId, region));
try {
ModifyInstanceAttributeRequest request = new ModifyInstanceAttributeRequest();
request.setInstanceId(instanceId);
request.setGroups(groupIds);
ec2Client().modifyInstanceAttribute(request);
} catch (AmazonServiceException e) {
if (e.getErrorCode().equals("InvalidInstanceID.NotFound")) {
throw new NotFoundException("AWS instance " + instanceId + " not found", e);
}