SMI: Method works in dev but not in prod

Hey all! I’m having a bit of a weird issue and wondering if somebody has experience with this.
I have a SMI function that downloads something with axios as an arraybuffer and then uploads it to an AWS S3 bucket. This works great when I test it using fdk run. When I fdk pack the app and test the app there, I get the following error (I can see it when I go to the custom app > View Log) :

An error occurred while uploading the file: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client at new NodeError (node:internal/errors:399:5) at ClientRequest.setHeader (node:_http_outgoing:645:11) at protocols.<computed>.request (/opt/framework/index.js:53:13) at /var/task/developer/node_modules/@aws-sdk/node-http-handler/dist-cjs/node-http-handler.js:72:25 at new Promise (<anonymous>) at NodeHttpHandler.handle (/var/task/developer/node_modules/@aws-sdk/node-http-handler/dist-cjs/node-http-handler.js:51:16) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async /var/task/developer/node_modules/@aws-sdk/middleware-serde/dist-cjs/deserializerMiddleware.js:5:26 { code: 'ERR_HTTP_HEADERS_SENT', '$metadata': { attempts: 1, totalRetryDelay: 0 } }

The piece of code that throws the error is the uploading with the s3Client, and it looks like this:

console.log("Sending upload command...");
      
      const uploadCommand = new PutObjectCommand({
        Bucket: options.iparams.recordingBucketName,
        Key: key,
        Body: recordingFile,
      });

      s3Client
        .send(uploadCommand)
        .then((response) => {
          console.log("File uploaded successfully!", response);
        })
        .catch((error) => {
          console.error("An error occurred while uploading the file:", error);
        });

      console.log("File uploaded successfully.");

Does anybody have any idea why this would happen?

Edit 1: I also just double checked if all my iparams and variables are correct. I thought maybe there was a problem there, but they all are correct in the SMI function.

Update:

  const s3Client = new S3Client({
        region: options.iparams.recordingBucketRegionAWS,
        credentials: {
          accessKeyId: options.iparams.recordingBucketAccessKey,
          secretAccessKey: options.iparams.recordingBucketSecretKey,
        },
      });
        let resaws = await s3Client.send(new ListObjectsV2Command({ Bucket: options.iparams.recordingBucketName }));
         console.log("AWS S3 access is available.", resaws);
       } catch (error) {
         console.error("Unable to access AWS S3:", error);
       }

A get to the bucket seems to work. So something is going wrong with the upload only. No clue what it is yet and im still looking further.

Solved this by generating a POST pre signed url using the aws-cdk lib, and then posting with Axios since I had that in the code anyway. Not the best solution but works for now.

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.