angelonardone / aws.ec2

AWS EC2 Client Package

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

# AWS EC2 Client Package #

**aws.ec2** is a simple client package for the Amazon Web Services (AWS) [Elastic Cloud Compute (EC2)](http://aws.amazon.com/ec2/) REST API, which can be used to monitor use of AWS web services.

To use the package, you will need an AWS account and enter your credentials into R. Your keypair can be generated on the [IAM Management Console](https://console.aws.amazon.com/iam/home?#security_credential) under the heading *Access Keys*. Note that you only have access to your secret key once. After it is generated, you need to save it in a secure location. New keypairs can be generated at any time if yours has been lost, stolen, or forgotten. 

By default, all **cloudyr** packages look for the access key ID and secret access key in environment variables. You can also use this to specify a default region. For example:

```R
Sys.setenv("AWS_ACCESS_KEY_ID" = "mykey",
           "AWS_SECRET_ACCESS_KEY" = "mysecretkey",
           "AWS_DEFAULT_REGION" = "us-east-1")
```

These can alternatively be set on the command line or via an `Renviron.site` or `.Renviron` file ([see here for instructions](http://cran.r-project.org/web/packages/httr/vignettes/api-packages.html)).

## Code Examples ##

The basic idea of the package is to be able to launch and control EC2 instances. You can read [this blog post from AWS](https://blogs.aws.amazon.com/bigdata/post/Tx3IJSB6BMHWZE5/Running-R-on-AWS) about how to run R on EC2.

A really simple example is to launch an instance that comes preloaded with an RStudio Server Amazon Machine Image (AMI):

```{r}
# describe the AMI (from: http://www.louisaslett.com/RStudio_AMI/)
describe_images("ami-7f9dc615")

# check your VPC and Security Group settings
## To actually use the 
s <- describe_subnets()
g <- describe_sgroups()

# launch the instance using appropriate settings
i <- run_instances(image = "ami-7f9dc615", 
                   type = "t2.micro", # <- you might want to change this
                   subnet = s[[1]], 
                   sgroup = g[[1]])

# RStudio Server will be available at the "publicIp" address returned in `i`
# If it doesn't load, check that the security group allows incoming HTTP

# stop and terminate the instances
stop_instances(i[[1]])
terminate_instances(i[[1]])
```


## Installation ##

[![CRAN](http://www.r-pkg.org/badges/version/aws.ec2)](http://cran.r-project.org/package=aws.ec2)
[![Travis Build Status](https://travis-ci.org/cloudyr/aws.ec2.png?branch=master)](https://travis-ci.org/cloudyr/aws.ec2) [![codecov.io](http://codecov.io/github/cloudyr/aws.ec2/coverage.svg?branch=master)](http://codecov.io/github/cloudyr/aws.ec2?branch=master)

This package is not yet on CRAN. To install the latest development version you can install from the cloudyr drat repository:

```R
# latest stable version
install.packages("aws.ec2", repos = c(getOption("repos"), "http://cloudyr.github.io/drat"))
```

Or, to pull a potentially unstable version directly from GitHub:

```R
if(!require("ghit")){
    install.packages("ghit")
}
ghit::install_github("cloudyr/aws.ec2")
```


---
[![cloudyr project logo](http://i.imgur.com/JHS98Y7.png)](https://github.com/cloudyr)

About

AWS EC2 Client Package


Languages

Language:R 99.3%Language:Shell 0.7%