Working on aws
Opened this issue · 1 comments
csgillespie commented
I've created two short functions that would be useful additions:
-
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 ) }
-
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 commented
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.