Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- }
Add Comment
Please, Sign In to add comment