是的,您可以为多个实例使用单个弹性IP。这可以通过以下步骤完成:
以下是示例 Python 代码,该代码使用 Boto3 库将弹性 IP 地址绑定到 EC2 实例:
import boto3
ec2 = boto3.client('ec2')
# Allocate a new Elastic IP address
response = ec2.allocate_address(Domain='vpc')
elastic_ip = response['PublicIp']
# Associate the Elastic IP address with an EC2 instance
response = ec2.associate_address(
AllocationId=elastic_ip['AllocationId'],
InstanceId='i-1234567890abcdef0'
)
print('Elastic IP address {} associated with instance i-1234567890abcdef0'.format(response['PublicIp']))