Created
May 2, 2011 22:01
-
-
Save bluepapa32/952460 to your computer and use it in GitHub Desktop.
Gradle で Amazon EC2 を操作してみる
This file contains hidden or 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
| 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}" | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
詳細は『Gradle で Amazon EC2 を操作してみる』