Thing I learned today
So if you ever use version 2 of the AWS ruby SDK, it’s worth noting that the docs are..well... they’re straight up unclear, to the point that the senior dev helping me on my project thought it’d be worth writing about.
REGARDLESS. Let’s say that you want to get the public ip address of a recently spun up ec2 instance. When you create a new instance, it'll give you the private dns name and private ip. However, it's worth noting that you need to reload the instance in order for it to give you the public ip address or public dns.
ex:
#makes new ec2 instance ec2 = Aws::EC2::Client.new(whatever your credentials are bro) res = Aws::EC2::Resource.new(client: ec2) inst = res.create_instances(image_id: ami-123456, min_count: 1, max_count: 1) #wait for that nonsense to get setup before proceeding inst[0].wait_until_running #returns data, but public_ip is nil & public_dns is "" inst[0].data #reload it by calling instances on our resource instance = res.instances(instance_ids: [inst[0].id]) #this works! instance[0].public_ip_address instance.first.public_dns_name












