å æ¥å ¬éãããaws-cliã®Perlã®ã©ããã¼ã¢ã¸ã¥ã¼ã«ãä½ãã¾ããã
Perlã§AWS EC2ã®APIãå©ãã«ã¯Net::Amazon::EC2ã便å©ã§ãã
ä¸æåã«æ¯ã¹ãã¨å¤ãã®APIã«å¯¾å¿ãã¦ããããããã(pullreq)ãéãã¨ããã«ãè¿äºãè¿ã£ã¦ããã®ã§ããæãã§ãã
ããVPCé¢é£ã®APIãµãã¼ããä¹ãããã¡ãã¡ãããããéãã®ãããã©ããªãã¨æã£ã¦ããã¨ãããå æ¥å ¬éãããAWSæ¬å®¶ã®aws-cliãã
- Pythonã§æ¸ããã¦ãã
- æ¢åã®ec2-*ã³ãã³ãã¯Javaãªãã§èµ·åæã«æéãããã
- ã¬ã¹ãã³ã¹ãJSONãªã®ã§parseãããã
- awsã³ãã³ãã ãã§EC2ãELBãªã©ããããªãµã¼ãã¹ã«å¯¾å¿ãã¦ã
ã¨ãããæãã ã£ããã§é±æ«ãµã¯ãã¨ã©ããã¼ã¢ã¸ã¥ã¼ã«ãæ¸ãã¦ã¿ã次第ã§ãã
ãããªæã:
use AWS::CLIWrapper; my $aws = AWS::CLIWrapper->new( region => 'us-west-1', ); my $res = $aws->ec2('describe-instances'); if ($res) { for my $rs ( @{ $res->{reservationSet} }) { for my $is (@{ $rs->{instancesSet} }) { print $is->{instanceId},"\n"; } } } else { warn $AWS::CLIWrapper::Error->{Code}; warn $AWS::CLIWrapper::Error->{Message}; }
ã»ã¼aws-cliã®ã³ãã³ãã«ã¾ããªãã§ããã£ã¦ããã¨ã¯
- JSONãPerlã®HashRefã«ãã¦è¿ã
- ã¨ã©ã¼ã ã£ãã undef è¿ã㦠$AWS::CLIWrapper::Error ã«è©°ãã¦è¿ã
ããããªãã§ãããçã§ã³ãã³ãå®è¡ãããããã¯æ¥½ã ã¨æãã¾ãã
ã¡ãªã¿ã«ãaws-cli(0.4.5)ã§regionæå®ã®ç°å¢å¤æ° AWS_DEFAULT_REGION ãå¹ããªãã®ã¯ã
ã®2è¡ãããã§æ²»ãã®ã§ã/usr/{,local/}lib/python2.6/site-packages/awscli/clidriver.py ã¨ãã«ãã clidriver.py ããããã°ããã¨æãã¾ãã
Enjoy!