Description Usage Arguments Value References See Also Examples
View source: R/run_instances.R
Run/launch a new EC2 Instance
1 2 3 4 |
image |
A character string containing an Amazon Machine Image (AMI) image ID or an object of class “ec2_image”. |
type |
A character string specifying the type of EC2 instance to use. See http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html for details of types and available options. |
min |
An integer specifying a minimum number of instances to launch. Defaults to 1. |
max |
An integer specifying a minimum number of instances to launch. Defaults to |
keypair |
A character string (max 255 character) containing the name of a keypair, or an object of class “ec2_keypair”. |
subnet |
A character string containing the name of a subnet, or an object of class “ec2_subnet”. |
sgroup |
A character vector specifying one or more Security Group IDs, or (a list of) objects of class “ec2_security_group”. |
userdata |
Optionally, a character string specifying a script to run during launch. See https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html. |
shutdown |
A character string specifying either “stop” or “terminate”, to control the behavior of a shutdown action taken from within the instance. |
token |
A (max 64-character) string containing a unique user-defined token. This can be used to ensure idempotency of requests in the event of a user-side failure. See http://docs.aws.amazon.com/AWSEC2/latest/APIReference/Run_Instance_Idempotency.html for details. |
tags |
A named list of tags. |
spot_options |
Optionally, an empty |
query_extra |
Optionally, additional query parameters to be passed to the RunInstances API. See https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_RunInstances.html for available parameters. |
launch_template |
A character string specifying a Launch Template ID. |
... |
Additional arguments passed to [ec2HTTP()]. |
A list
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EC2_GetStarted.html http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_RunInstances.html
describe_instances()
, start_instances()
, terminate_instances()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | ## Not run:
# Rstudio instance for interactive use
## RStudio AMIs from: http://www.louisaslett.com/RStudio_AMI/
s <- describe_subnets()
g <- create_sgroup("my_security_group", "a security group", vpc = s[[1]])
i <- run_instances(image = "ami-7f9dc615",
type = "t2.micro",
subnet = s[[1]],
sgroup = g[[1]])
stop_instances(i[[1]])
terminate_instances(i[[1]])
# Generic linux image
## create an SSH keypair
my_keypair <- create_keypair("r-ec2-example")
pem_file <- tempfile(fileext = ".pem")
cat(my_keypair$keyMaterial, file = pem_file)
## script to install R, RStudio, and awspack
sh <- system.file("rstudio.sh", package = "aws.ec2")
## run instance
i <- run_instances(image = "ami-97785bed",
type = "t2.micro",
userdata = readBin(sh)
keypair = my_keypair)
)
try(authorize_ingress(my_sg))
instance_ip <- associate_ip(i, allocate_ip("vpc"))$publicIp
# log in to instance
library("ssh")
session <- ssh::ssh_connect(paste0("ec2user@", instance_ip),
keyfile = pem_file, passwd = "ec2password")
# write a quick little R script to execute
cat("'hello world!'\n", file = "helloworld.R")
# upload it to instance
invisible(ssh::scp_upload(session, "helloworld.R"))
# execute script on instance
x <- ssh::ssh_exec_wait(session, "Rscript helloworld.R")
## disconnect from instance
ssh_disconnect(session)
# kill instance
stop_instances(i[[1]])
terminate_instances(i[[1]])
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.