Skip to content

Instantly share code, notes, and snippets.

@bluepapa32
Created May 4, 2011 16:01
Show Gist options
  • Save bluepapa32/955470 to your computer and use it in GitHub Desktop.
Save bluepapa32/955470 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)
task 'ec2-import-keypair' << {
ec2.describeRegions().regions.each { region ->
ec2.endpoint = region.endpoint
ec2.importKeyPair(new ImportKeyPairRequest(keyName, file(publicKeyFile).text))
}
}
@bluepapa32
Copy link
Author

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