Cannot get AWS Lambda to PutObject to S3 in same account no matter what

Viewed 240

I am trying to write a lambda to run FFMPEG in an AWS lambda. I have done this before at another workplace so I know that it is possible.

The log shows that I make a Temporary URL to read the file in, it processes with FFMPEG, I pipe the output to a byte[] which is showing data in it, and then I try to do an S3 PutObjectRequest, which always fails with this message:

The request signature we calculated does not match the signature you provided. Check your key and signing method.

The S3 client is the same credentials that I use automated all the time to upload files to S3 from different servers at different locations of our company. I have tried a couple different IAMs to no effect.

I am not trying to do any sort of signature whatsoever. I am simply doing this:

        var putRequest = new PutObjectRequest
        {
            BucketName = m.Groups["bucket"].Value,
            Key = m.Groups["key"].Value,
            InputStream = new MemoryStream(Encoding.UTF8.GetBytes(data ?? "")),
            CannedACL = S3CannedACL.PublicRead,
            ContentType = MimeTypes.GetMimeType(Path.GetExtension(m.Groups["key"].Value)),
            DisablePayloadSigning = true,
        };
        putRequest.Headers.ContentLength = data.Length;
        _context.Logger.LogLine($"Saving file to bucket '{putRequest.BucketName}' and key '{putRequest.Key}' and content type '{putRequest.ContentType}' and content length {putRequest.Headers.ContentLength}");

        try
        {
            await _s3Client.PutObjectAsync(putRequest);
        }
        catch (AmazonS3Exception s3x)
        {
            _context.Logger.LogLine($"S3 Exception: {s3x.Message}");
        }

I have checked bucket and key and they are correct. Data.length is greater than 0. Content type is "audio/mpeg", which is correct for .mp3. The data is there to be written.

My lambda is running under AWSLambda_Full_Access with the following additional rights granted:

{
"Version": "2012-10-17",
"Statement": [
    {
        "Sid": "VisualEditor0",
        "Effect": "Allow",
        "Action": [
            "s3:ListStorageLensConfigurations",
            "s3:ListAccessPointsForObjectLambda",
            "s3:GetAccessPoint",
            "s3:PutAccountPublicAccessBlock",
            "s3:GetAccountPublicAccessBlock",
            "s3:ListAllMyBuckets",
            "s3:*",
            "s3:ListAccessPoints",
            "s3:ListJobs",
            "s3:PutStorageLensConfiguration",
            "s3:ListMultiRegionAccessPoints",
            "s3:CreateJob"
        ],
        "Resource": "*"
    }
]
}

Does anyone have any ideas what else I could be missing? I have been stuck on this one problem for over 3 days now and have tried everything I can think of, so it must be something I'm not thinking of.

Thanks.

0 Answers
Related