Sample Header Ad - 728x90

How to get private IP address of EC2 after spinning the AWS from local machine/ at Jenkins outside AWS

4 votes
1 answer
2005 views
Assume we already spin the AWS using cloudformation plugin from Jenkins outside AWS and now, how to get private IP address after spinning the AWS at my local machine/jenkins using any API methods? I tried ruby aws-sdk, REST API methods to get the private ip outside AWS (at my local) and I'm getting timed out for the connection. Here are some examples that did not yield the ip address/EC2 objects and getting timeout - #using ruby aws-sdk require 'rubygems' require 'aws-sdk-v1' require 'aws-sdk' AWS.config(:region => "xxxxx", :access_key_id => "xxxxx", :secret_access_key => "xxxxx") ec2 = AWS::EC2.new( :region => "xxxxxx", :access_key_id => "xxxx", :secret_access_key => "xxxxxxx") ec2.instances.each do |test| puts test.id end #using REST API client - require 'rubygems' require 'rest-client' url = "https://ec2.amazonaws.com/?Action=DescribeNatGateways&ImageId=xxxxxxx&access_key_id=xxxxxx&secret_access_key=xxxxxxxx " response=RestClient::Request.execute(:url =>url, :method => :get, :verify_ssl => false) puts response Tried uploading the IP address contained text file to S3 and then reading it back - --------------cloudformation Json contains the following --------- "wget -qO- http://169.254.169.254/latest/meta-data/local-pv4 >>dockeriseleniumgrid_ip_address\n", "aws s3 cp dockeriseleniumgrid_ip_address s3://xxxxx/dockeriseleniumgrid_ip_address\n" ----------tried reading it from s3 and writing to local machine -------- require 'aws/s3' S3ID = "xxxxx" S3KEY = "xxxx" # include AWS::S3 AWS::S3::Base.establish_connection!( :access_key_id => S3ID, :secret_access_key => S3KEY ) bucket = AWS::S3::Bucket.find("dockeriseleniumgrid_ip_address") File.open("ip_address.txt", "w") do |f| f.write(bucket.objects.read) end I'm new to AWS and appreciate if anyone can help
Asked by user176867 (41 rep)
Nov 18, 2016, 08:12 PM
Last activity: Jul 3, 2025, 06:07 AM