AWSSDK.S3 C# Dll Errors in PowerShell console but not in ISE (The request signature we calculated does not match the signature you provided.)

Viewed 96

I am trying to retrieve a key from AWS S3 storage. My main goal is to have a dll that I can execute as a com object from a delphi based system.

This works perfectly for "Normal" keys, however we have a key that was saved as "documents/00012000/12368."

(Yes, there is a period at the end which is a special character for S3, however according to AWS Documentation this should work via the SDK).

When I try to read the object I receive the error "The request signature we calculated does not match the signature you provided. Check your key and signing method" when I run this dll through the PowerShell console, however if I run the same code through the PowerShell ISE it executes successfully and retrieves the file.

The method in the dll is:

public byte[] getFile(string Bucket, string Key)
        {
            var credentials = new Amazon.Runtime.BasicAWSCredentials("my key", "my secret");
            
            // Create a client
            AmazonS3Client client = new AmazonS3Client(credentials, RegionEndpoint.APSoutheast2);
            
            // Create a GetObject request
            GetObjectRequest request = new GetObjectRequest
            {
                BucketName = Bucket,
                Key = Key
            };
            MemoryStream outputstream = new MemoryStream();
            // Issue request and remember to dispose of the response
            using (GetObjectResponse response = client.GetObject(request))
            {
                // Save object to local file
                //response.WriteResponseStreamToFile(@"C:\temp\Test.pdf");
                response.ResponseStream.CopyTo(outputstream);
                return outputstream.ToArray();
            }

        }

If I try to check if the file exists I also get an error ("Error making request with Error Code Forbidden and Http Status Code Forbidden. No further error information was returned by the service.), and once again, through the ISE it works.

public bool fileExists(string Bucket, string Key)
        {
            // Create a client
            var credentials = new Amazon.Runtime.BasicAWSCredentials("my key", "my secret");
            
            // Create a client
            AmazonS3Client client = new AmazonS3Client(credentials, RegionEndpoint.APSoutheast2);

            S3FileInfo file = new S3FileInfo(client, Bucket, Key);
            return file.Exists;
            
        }

As a side note I have also created a test .net framework forms app to call the .net dll to test, and it works.

I am at a loss as to why the same code is acting differently in the ISE, and from a .net form exe, to the PowerShell console and as a com object called from delphi.

Has anyone seen this behaviour before?

I have tried compiling the dll in multiple frameworks from 4.5.2 up to 4.7.2 with no change. I have also tried using the PowerShell modules with the following code and receive the same errors:

$Bucket="mybucket"
$s3file="documents/00012000/12368."
Read-S3Object -BucketName $Bucket -accesskey mykey -secretkey mysecret -region ap
-southeast-2 -Key $s3file -File "d:\temp\file.pdf"

I know avoiding naming a key with a period at the end would be ideal, however I currently cannot control that.

AWSSDK.Core Version 3.7.1.1 (Latest Stable) AWSSDK.S3 Version 3.7.1.17 (Latest Stable)

PowerShell version 5.1.19041.1023

0 Answers
Related