Skip to content

Commit

Permalink
add extended tutorial to main pkg docs (closes #32)
Browse files Browse the repository at this point in the history
  • Loading branch information
leeper committed Jul 25, 2018
1 parent c27ba86 commit 7cc5286
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 8 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ Imports:
base64enc
Suggests:
testthat,
aws.ec2metadata
aws.ec2metadata,
ssh
URL: https://github.com/cloudyr/aws.ec2
BugReports: https://github.com/cloudyr/aws.ec2/issues
RoxygenNote: 6.0.1
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export(delete_subnet)
export(delete_tags)
export(delete_volume)
export(delete_vpc)
export(deregister_image)
export(describe_gateways)
export(describe_images)
export(describe_instances)
Expand Down
76 changes: 76 additions & 0 deletions R/aws.ec2-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,83 @@
#' @docType package
#' @title AWS EC2 Client Package
#' @description A simple client package for the Amazon Web Services (AWS) Elastic Cloud Compute (EC2) REST API.
#' @details The examples below provide a complete workflow for setting up EC2 via this package and launching an instance.
#' @author Thomas J. Leeper <[email protected]>
#' @examples
#' \dontrun{
#' # check credentials
#' aws.signature::locate_credentials()
#'
#' # check EC2 account settings
#' account_attrs()
#'
#' # create an SSH keypair in EC2 and save locally
#' my_keypair <- create_keypair("r-ec2-example")
#' pem_file <- tempfile(fileext = ".pem")
#' cat(my_keypair$keyMaterial, file = pem_file)
#'
#' # create a "security group" allowing access from current IP
#' my_sg <- create_sgroup("r-ec2-sg", "Allow my IP")
#' ## authorize access from this IP
#' try(authorize_ingress(my_sg))
#' try(authorize_egress(my_sg))
#'
#' # find an EC2 AMI, like: http://www.louisaslett.com/RStudio_AMI/
#' my_image <- "ami-3b0c205e"
#'
#' # Launch the instance using appropriate settings
#' my_inst <- run_instances(image = my_image,
#' type = "t2.nano",
#' sgroup = my_sg,
#' keypair = my_keypair)
#' Sys.sleep(5L) # wait for instance to boot
#'
#' # allocate an IPv4 address
#' ip <- allocate_ip("vpc")
#'
#' # associate IP with instane
#' associate_ip(my_inst, ip)
#'
#'
#' # login to instance through browser
#' utils::browseURL(ip)
#'
#' # login to instance through R
#' library("ssh")
#' session <- ssh::ssh_connect(paste0("ubuntu@", instance_ip), keyfile = pem_file, passwd = "rstudio")
#'
#' # write a quick little R script to execute
#' cat("'hello world!'\nsprintf('2+2 is %d', 2+2)\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:ssh_disconnect(session)
#'
#'
#' # create an image from the instance to reuse later
#' my_image <- create_image(my_inst, "My Rstudio Image")
#'
#'
#' # when finished, completely cleanup all EC2 material
#' ## stop and terminate the instance
#' stop_instances(i[[1L]])
#' terminate_instances(i[[1L]])
#'
#' ## revoke access from this IP to security group
#' try(revoke_ingress(my_sg))
#' try(revoke_egress(my_sg))
#'
#' ## delete keypair
#' delete_keypair(my_keypair)
#'
#' ## release IP address
#' release_ip(ips[[1L]])
#'
#' }
#' @keywords package
#' @seealso [account_attrs()] [run_instances()]
NULL
8 changes: 5 additions & 3 deletions R/create_image.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#' @template dots
#' @return A list.
#' @references
#' <http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/creating-an-ami.html>
#' <http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_CopyImage.html>
#' <http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_CreateImage.html>
#' @examples
Expand Down Expand Up @@ -75,15 +76,16 @@ function(
return(r)
}

# \url{http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/creating-an-ami.html}
# \url{http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_RegisterImage.html}
#' @keywords images
# <http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_RegisterImage.html>
# @keywords images
register_image <- function() {

# NEED TO DO THIS

}

#' @rdname create_ami
#' @export
deregister_image <- function(image, ...) {
query <- list(Action = "DeregisterImage",
ImageId = get_imageid(image))
Expand Down
1 change: 1 addition & 0 deletions R/create_vpc.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#' @template dots
#' @return For `create_vpc`, a list of class \dQuote{ec2_vpc}. For `delete_vpc`, a logical indicating whether the operation succeeded.
#' @references
#' <https://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Subnets.html>
#' <http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_CreateVpc.html>
#' <http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DeleteVpc.html>
#' @examples
Expand Down
1 change: 0 additions & 1 deletion R/ebs_snapshots.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#' @rdname ebs_snapshots
#' @title Elastic Block Store Snapshots
#' @description Manage Elastic Block Store (EBS) volumes for EC2
#' @param volume An object of class \dQuote{ec2_ebs_volume} or a character string containing a volume ID.
#' @template volume
#' @template snapshot
#' @param description \dots
Expand Down
79 changes: 79 additions & 0 deletions man/aws.ec2-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions man/create_ami.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions man/ebs_snapshots.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/vpcs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7cc5286

Please sign in to comment.