Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: PERL to AWS

by jo37 (Deacon)
on May 07, 2020 at 15:53 UTC ( [id://11116550]=note: print w/replies, xml ) Need Help??


in reply to PERL to AWS

I've been using AWS::CLIWrapper for some time. It has the advantage that you can do everything the CLI offers.

Greetings,
-jo

$gryYup$d0ylprbpriprrYpkJl2xyl~rzg??P~5lp2hyl0p$

Replies are listed 'Best First'.
Re^2: PERL to AWS
by haukex (Archbishop) on May 17, 2020 at 19:36 UTC
    I've been using AWS::CLIWrapper for some time.

    Thank you for pointing this out, it inspired me to release IPC::Run3::Shell::CLIWrapper, which is a more generic tool, but allows me to write my previous example as the following. The set-up may look a little more complicated, but the actual calls are much simplified. And since I wrote IPC::Run3::Shell, I can be certain of its behavior :-)

    use warnings; use strict; use IPC::Run3::Shell::CLIWrapper; use JSON::PP qw/decode_json/; use Data::Dumper; my $s3api = IPC::Run3::Shell::CLIWrapper->new( { fail_on_stderr => 1, stdout_filter => sub { $_=decode_json($_) } }, qw/ aws --profile MyProfile --output json s3api /); my $buckets = $s3api->list_buckets; print Dumper($buckets);

      Taking a real life example, I don't see an advantage in using IPC::Run3::Shell::CLIWrapper over AWS::CLIWrapper:

      #!/usr/bin/perl use strict; use warnings; use AWS::CLIWrapper; use Data::Dumper; my $aws = AWS::CLIWrapper->new(profile => 'my_profile') or die $AWS::CLIWrapper::Error->{Message}; sub gethosts { my $name = shift; my $hosts = $aws->ec2('describe-instances' => { filters => [{Name => 'tag:Name', Values => [$name]}], query => 'Reservations[*].Instances[*].{Id:InstanceId,Addr:Pri +vateIpAddress,Zone:Placement.AvailabilityZone,Name:(Tags[?Key==`Name` +])[0].Value}'}) or die "$AWS::CLIWrapper::Error->{Message}"; return [map {@$_} @$hosts]; } my $hosts = gethosts('*something*'); print Dumper($hosts);

      Doesn't this feel very "perlish"? :-)
      Maybe I'm missing the point.

      Greetings,
      -jo

      $gryYup$d0ylprbpriprrYpkJl2xyl~rzg??P~5lp2hyl0p$

        Sure, I wasn't saying there's something wrong with AWS::CLIWrapper (I haven't inspected it in detail), and it definitely provides some more sugar for accessing AWS that my module doesn't provide. My module just has two advantages in general: it's generic, i.e. it can be used for any command-line tools like git, docker, aws, etc., and second, a big advantage for someone like myself who thinks a lot about how to run external commands properly, I know that the module will properly handle passing any command-line arguments I throw at it, and the return values and behaviors are well-defined too.

        Maybe I'm missing the point.

        My point was: thanks for the inspiration :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11116550]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-26 00:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found