Skip to content

Bad request error when using Paws::S3::SelectObjectContent #403

@hakonhagland

Description

@hakonhagland

According to the documentation the following script should work:

use feature qw(say);
use strict;
use warnings;
use Data::Dumper;
use Paws;
 
my $s3 = Paws->service('S3', region => 'us-east-2');
my $bucket = 'hakonhagland-second-bucket';
my $obj_content = $s3->SelectObjectContent(
    Bucket              => $bucket,
    Expression          => 'SELECT * FROM S3Object',
    ExpressionType      => 'SQL',
    InputSerialization  => {
        JSON => {
            Type => 'LINES',
        }
    },
    Key                 => 'test.json',
    OutputSerialization => {
        JSON => {}
    } );
print Dumper( $obj_content );

However, it fails (Ubuntu 21.04, perl 5.32) with:

$ p.pl
Paws::S3 is not stable / supported / entirely developed at /home/hakon/perlbrew/perls/perl-5.32.0/lib/site_perl/5.32.0/Paws/S3.pm line 2.
Bad Request
 
Trace begun at /home/hakon/perlbrew/perls/perl-5.32.0/lib/site_perl/5.32.0/Paws/Net/RestXMLResponse.pm line 25
Paws::Net::RestXMLResponse::process('Paws::Net::RestXMLResponse=HASH(0x55a69a6fcf80)', 'Paws::S3::SelectObjectContent=HASH(0x55a69abe9970)', 'Paws::Net::APIResponse=HASH(0x55a69ab15a08)') called at /home/hakon/perlbrew/perls/perl-5.32.0/lib/site_perl/5.32.0/Paws/Net/Caller.pm line 46
Paws::Net::Caller::caller_to_response('Paws::Net::Caller=HASH(0x55a699e5d948)', 'Paws::S3=HASH(0x55a69a64fa60)', 'Paws::S3::SelectObjectContent=HASH(0x55a69abe9970)', 'Paws::Net::APIResponse=HASH(0x55a69ab15a08)') called at /home/hakon/perlbrew/perls/perl-5.32.0/lib/site_perl/5.32.0/Paws/Net/RetryCallerRole.pm line 19
Paws::Net::RetryCallerRole::do_call('Paws::Net::Caller=HASH(0x55a699e5d948)', 'Paws::S3=HASH(0x55a69a64fa60)', 'Paws::S3::SelectObjectContent=HASH(0x55a69abe9970)') called at /home/hakon/perlbrew/perls/perl-5.32.0/lib/site_perl/5.32.0/Paws/S3.pm line 521
Paws::S3::SelectObjectContent('Paws::S3=HASH(0x55a69a64fa60)', 'Bucket', 'hakonhagland-second-bucket', 'Expression', 'SELECT * FROM S3Object', 'ExpressionType', 'SQL', 'InputSerialization', 'HASH(0x55a69a621158)', 'Key', 'test.json', 'OutputSerialization', 'HASH(0x55a69a6508a0)') called at p.pl line 11

I checked the source code in Paws/Net/RestXmlCaller.pm line 237, it computes $xml_body as:

<OutputSerialization><JSON></JSON></OutputSerialization>SQL<InputSerialization><JSON><Type>LINES</Type></JSON></InputSerialization>SELECT * FROM S3Object

Notice the free text (not within XML tags) SQL and SELECT * FROM S3Object. According to the AWS documentation, the correct XML body should look like this:

<OutputSerialization><JSON></JSON></OutputSerialization><ExpressionType>SQL</ExpressionType><InputSerialization><JSON><Type>LINES</Type></JSON></InputSerialization><Expression>SELECT * FROM S3Object</Expression>

See also this question on stackoverflow.com

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions