Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S3 selectObjectContent SignatureDoesNotMatch error #417

Open
wcheek opened this issue Jan 22, 2024 · 0 comments
Open

S3 selectObjectContent SignatureDoesNotMatch error #417

wcheek opened this issue Jan 22, 2024 · 0 comments

Comments

@wcheek
Copy link

wcheek commented Jan 22, 2024

I'm trying to use S3 Select to get filtered data from an S3 object using my Flutter app.

I'm loading temporary IAM credentials from a successful Cognito login using Amplify Auth. These credentials work with the S3 Client to listObjectsV2 and getObject, but there is an issue with selectObjectContent. From scouring StackOverflow, this error usually occurs with bad credentials, but the credentials are working for everything but this particular method.

This error occurs even when I try to selectObjectContent on a bucket that I don't have permission to access, and for objects that don't exist. Something is wrong with the signed request.

import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
import 'package:amplify_flutter/amplify_flutter.dart';
import 'package:aws_client/s3_2006_03_01.dart';

/// Getting credentials from my session
    final cognitoPlugin = Amplify.Auth.getPlugin(AmplifyAuthCognito.pluginKey);
    final result = await cognitoPlugin.fetchAuthSession();
    final accessKeyId = result.credentialsResult.value.accessKeyId;
    final secretAccessKey = result.credentialsResult.value.secretAccessKey;
    final sessionToken = result.credentialsResult.value.sessionToken;
    final expiration = result.credentialsResult.value.expiration;

/// Create s3 client
    s3Client = S3(
      region: region,
      credentials: AwsClientCredentials(
        accessKey: accessKeyId,
        secretKey: secretAccessKey,
        sessionToken: sessionToken,
        // expiration: expiration,
      ),
    );

/// Try to selectObjectContent
    final response = await s3Client.selectObjectContent(
      key: fileKey,
      bucket: ftpBucketName,
      expression: r"Select * from S3Object",
      expressionType: ExpressionType.sql,
      inputSerialization: InputSerialization(
        // compressionType: CompressionType.gzip,
        csv: CSVInput(
          fileHeaderInfo: FileHeaderInfo.use,
          recordDelimiter: r"\n",
          fieldDelimiter: ",",
          quoteCharacter: '"',
          quoteEscapeCharacter: '"',
          comments: "#",
        ),
      ),
      outputSerialization: OutputSerialization(
        csv: CSVOutput(
          quoteFields: QuoteFields.asneeded,
          recordDelimiter: r"\n",
          fieldDelimiter: ",",
          quoteCharacter: '"',
          quoteEscapeCharacter: '"',
        ),
      ),
    );

Output:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: SignatureDoesNotMatch null: The request signature we calculated does not match the signature you provided. Check your key and signing method.
#0      RestXmlProtocol.sendRaw (package:aws_client/src/shared/src/protocol/rest_xml.dart:100:9)
<asynchronous suspension>
#1      S3.selectObjectContent (package:aws_client/src/generated/s3/v2006_03_01.dart:11444:21)
<asynchronous suspension>
#2      AWSUtils.selectDataFromFile (package:web_app/network/aws.dart:99:22)
<asynchronous suspension>
#3      _FileViewerState._loadCSV (package:web_app/ui/file_list_page.dart:83:22)
<asynchronous suspension>
@wcheek wcheek changed the title S3 selectObjectContent SignatureDoesNotMatch error S3 selectObjectContent SignatureDoesNotMatch error Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant