Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working on aws #20

Open
csgillespie opened this issue Oct 24, 2016 · 1 comment
Open

Working on aws #20

csgillespie opened this issue Oct 24, 2016 · 1 comment

Comments

@csgillespie
Copy link
Contributor

I've created two short functions that would be useful additions:

  1. Get the aws instance id. Only run on an actual aws instance:

    # Only run on aws instance
    # Get the instance id
    get_instance_id = function(verbose = FALSE) {
     system(
       "curl http://instance-data/latest/meta-data/instance-id",
       intern = TRUE,
       ignore.stderr = !verbose
     )
    }
    
  2. Check if we are running on an instance.

    is_instance = function() {
     hostname <- system("hostname -d", intern = TRUE)
     # Grep could be made better by checking for eu-west-1, etc.
     length(grep("*.compute.internal$", hostname)) > 1
    }
    

Example use case:

run = function() {
   if(is_instance()) {
       instance_id = get_instance_id()
       on.exit(terminate_instances(instance_id))
   }
   simulate_stuff()
}
@leeper
Copy link
Member

leeper commented Apr 2, 2018

Thanks - I'm just getting to this for some reason. The aws.ec2metadata package now provides an is_ec2() function that checks whether R is running on EC2. The other ideas are great and I'll try to implement them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants