cbtshare has asked for the wisdom of the Perl Monks concerning the following question:

Hey all, I am using the perl AWS api( https://metacpan.org/pod/VM::EC2) to make a script, the module is installed, but when I run a sample script, I am getting the error below.I search on google and cant seem to find anything wrong.Can anyone assist? Thank you

Can't call method "architecture" on an undefined value at aws.pl line +18.
#!/usr/local/perl-5.23.3/perl use strict; use warnings; use VM::EC2; my $ec2 = VM::EC2->new(-access_key => "5454fgfffh", -secret_key => "dscsdcsd", -endpoint => 'http://ec2.amazonaws.com ); #Get image my $image = $ec2->describe_images('ami-469e1d2a'); # get some information about the image my $architecture = $image->architecture; my $description = $image->description; my @devices = $image->blockDeviceMapping; for my $d (@devices) { print $d->deviceName,"\n"; print $d->snapshotId,"\n"; print $d->volumeSize,"\n"; }

Replies are listed 'Best First'.
Re: Perl AWS Error
by Your Mother (Archbishop) on Feb 12, 2016 at 19:17 UTC

    I have never used this library but I do expect this change will shed some light on your problem (namely that your $image object is never actually created)–

    my $ec2 = VM::EC2->new( -access_key => "5454fgfffh", -secret_key => "dscsdcsd", -endpoint => 'http://ec2.amazonaws.com', -raise_error => 1 );

    Note that the code you posted is slightly broken (missing quote in the args to new) and will not even compile as it stands.

Re: Perl AWS Error
by salva (Canon) on Feb 12, 2016 at 21:25 UTC
Re: Perl AWS Error
by cbtshare (Monk) on Feb 12, 2016 at 20:46 UTC

    Thank you for your reply -raise_error helped alot, the code is verbatim from the module webpage, and it does compile if I just have the lines below.

    my $ec2 = VM::EC2->new(-access_key => 'wew23232', -secret_key => '3232323', -endpoint=> 'http://ec2.amazonaws.com', ); #Get image my $image = $ec2->describe_images('ami-469e1d2a');

    I also do have an image created and set it as the image code $ec2->describe_images('ami-469e1d2a'), but was getting an error which was solved by sync the server clock.

    Now I am getting the error from the modified code

    [595] No such device or address, at API call 'DescribeImages')

    #!/usr/local/perl-5.23.3/perl use strict; use warnings; use VM::EC2; my $ec2 = VM::EC2->new(-access_key => 'AKIAJQc', -secret_key => 'J3jCAvb2+six', -endpoint=> 'http://ec2.amazonaws.com', -raise_error=> '1', -region=> 'sa-east-1a', ); #Get image my $image = $ec2->describe_images('ami-469e1d2a'); # get some information about the image my $architecture = $image->architecture; my $description = $image->description; my @devices = $image->blockDeviceMapping; for my $d (@devices) { print $d->deviceName,"\n"; print $d->snapshotId,"\n"; print $d->volumeSize,"\n"; }
Re: Perl AWS Error
by CoVAX (Beadle) on Feb 14, 2016 at 08:15 UTC

    I have not used this module nor tested the following. Having said that, try:

    my $image = $ec2->describe_images(-image_id=>'ami-12345');

    See VM::EC2::Image

Re: Perl AWS Error
by perlfan (Parson) on Feb 15, 2016 at 20:26 UTC
Re: Perl AWS Error
by cbtshare (Monk) on Feb 16, 2016 at 22:43 UTC

    Thank you all for your replies and help.. The issue was that when I put in region, I had it as sa-east-1a, but that is the availability zone, region is sa-east-1 Thank you