Skip to content

Instantly share code, notes, and snippets.

@bluepapa32
Created May 2, 2011 22:01
Show Gist options
  • Select an option

  • Save bluepapa32/952460 to your computer and use it in GitHub Desktop.

Select an option

Save bluepapa32/952460 to your computer and use it in GitHub Desktop.
Gradle で Amazon EC2 を操作してみる
import com.amazonaws.*;
import com.amazonaws.auth.*;
import com.amazonaws.services.ec2.*;
import com.amazonaws.services.ec2.model.*;
buildscript {
repositories { mavenCentral() }
dependencies { classpath 'com.amazonaws:aws-java-sdk:1.1.9' }
}
def credentials = new PropertiesCredentials(
new File(System.properties['user.home'],
'.aws/AwsCredentials.properties'))
def ec2 = new AmazonEC2Client(credentials)
if (hasProperty('region')) ec2.endpoint = "https://ec2.${region}.amazonaws.com"
task 'start' << {
ec2.startInstances(new StartInstancesRequest([instanceId]))
}
task 'stop' << {
ec2.stopInstances(new StopInstancesRequest([instanceId]))
}
task 'status' << {
desc = ec2.describeInstances(new DescribeInstancesRequest().withInstanceIds([instanceId]))
inst = desc.reservations[0].instances[0]
println "${inst.state.name}: ${inst.publicDnsName}"
}
@bluepapa32
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment