An auto-assigned public address lasts only while the instance runs. Stop it and the address returns to the pool; start it and a new one arrives, while the private address stays:
i=i-0d87b52d19abc8fc5
q='Reservations[0].Instances[0].[State.Name,PublicIpAddress,PrivateIpAddress]'
aws ec2 stop-instances --instance-ids $i --output text \
--query "StoppingInstances[0].[PreviousState.Name,CurrentState.Name]"
aws ec2 wait instance-stopped --instance-ids $i
aws ec2 describe-instances --instance-ids $i --query "$q" --output text
aws ec2 start-instances --instance-ids $i --output text \
--query "StartingInstances[0].[PreviousState.Name,CurrentState.Name]"
aws ec2 wait instance-running --instance-ids $i
aws ec2 describe-instances --instance-ids $i --query "$q" --output textrunning stopping stopped None 172.31.8.174 stopped pending running 3.238.80.219 172.31.8.174
A DNS record for 54.236.40.252 would now send visitors to a stranger. An Elastic IP stays yours until you release it: aws ec2 allocate-address --domain vpc returned 184.193.139.173, and associate-address moved it onto the instance, whose public DNS name followed it. Since February 2024 every public IPv4 address costs USD 0.005 an hour, attached or idle, so release what you do not use (Cost Traps). After disassociate-address and release-address, the instance received a fresh auto-assigned address, 34.201.1.172.
For a domain, add an A record for the Elastic IP in a Route 53 24 hosted zone (or at your registrar). Route 53 alias records can also point the bare example.com at CloudFront 24 or a load balancer, which a CNAME cannot do at a zone apex.