Scalr\Service\Aws\Ec2\V20150415\Ec2Api::associateAddress PHP Method

associateAddress() public method

Associates an Elastic IP address with an instance. This action applies to both EC2 and VPC Elastic IP addresses. EC2: If the IP address is currently assigned to another instance, the IP address is assigned to the new instance. VPC: If the IP address is currently assigned to another instance, Amazon EC2 returns an error unless you specify the AllowReassociation parameter This is an idempotent operation. If you enter it more than once, Amazon EC2 does not return an error
public associateAddress ( Scalr\Service\Aws\Ec2\DataType\AssociateAddressRequestData $request ) : boolean | string
$request Scalr\Service\Aws\Ec2\DataType\AssociateAddressRequestData
return boolean | string Returns associationId (for VPC Elastic IP addresses) or boolean TRUE (for others) on success.
    public function associateAddress(AssociateAddressRequestData $request)
    {
        $result = false;
        $options = $request->getQueryArrayBare();
        $response = $this->client->call(ucfirst(__FUNCTION__), $options);
        if ($response->getError() === false) {
            $sxml = simplexml_load_string($response->getRawContent());
            if ((string) $sxml->return != 'true') {
                throw new Ec2Exception(sprintf('Amazon Ec2 could not associate elastic IP address. It returned "%s"', $sxml->return));
            }
            $result = $this->exist($sxml->associationId) ? (string) associationId : true;
        }
        return $result;
    }
Ec2Api