Skip to content

Instantly share code, notes, and snippets.

@toshihirock
Last active August 29, 2015 14:12
Show Gist options
  • Save toshihirock/19b306c6f65d5b63ee9e to your computer and use it in GitHub Desktop.
Save toshihirock/19b306c6f65d5b63ee9e to your computer and use it in GitHub Desktop.
EC2のリストを取得する
@Grapes([
@Grab(group='commons-codec', module='commons-codec', version='1.10'),
@Grab(group='com.amazonaws', module='aws-java-sdk', version='1.9.13')
])
import com.amazonaws.services.ec2.*
import com.amazonaws.auth.*
import com.amazonaws.auth.profile.*
import com.amazonaws.regions.*
credentials = new ProfileCredentialsProvider().getCredentials()
ec2 = new AmazonEC2Client(credentials)
ec2.setRegion(Region.getRegion(Regions.AP_NORTHEAST_1))
result = ec2.describeInstances()
result.reservations.instances.each {
println "${it.tags[0].value[0]}\t${it.state.name[0]}\t${it.publicDnsName[0]}"
}
@toshihirock
Copy link
Author

  • ~/.ssh/configにログイン対象のユーザー名、KeyPair、ホスト名を指定しておくこと
  • ~/.aws/credentialsの設定をしておくこと
  • groovy ec2list.groovy| percol | cut -f 3 | xargs -o -n 1 ssh

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