Created
June 16, 2012 13:05
-
-
Save imeredith/2941290 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def createContext = { | |
ContextBuilder.newBuilder(new AWSEC2ProviderMetadata) | |
.credentials("<>", "<>") | |
.buildView(classOf[AWSEC2ComputeServiceContext]) | |
.unwrap(classOf[RestContext[AWSEC2Client, AWSEC2AsyncClient]]) | |
} | |
implicit def syncApi = createContext.getApi | |
def createInstance(imageId: String, hwType: String, group: String, key: String)(implicit c: AWSEC2Client, region: String = null) = { | |
val opts = AWSRunInstancesOptions.Builder.asType(hwType).withSecurityGroup(group).withKeyName(key) | |
val instances = c.getInstanceServices.runInstancesInRegion(region,null,imageId,1,1,opts) | |
instances.headOption | |
} | |
def destroyInstance(id: String)(implicit c: AWSEC2Client, region: String = null) = { | |
val instances = c.getInstanceServices.terminateInstancesInRegion(region, id) | |
instances.headOption | |
} | |
def runningInstance(id: String)(implicit c: AWSEC2Client, region: String = null): Option[RunningInstance] = { | |
val instance = c.getInstanceServices.describeInstancesInRegion(region, id).headOption | |
for { | |
i <- instance | |
runningInstance <- i.headOption | |
} yield runningInstance | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment