Access denied error when trying to upload to AWS Transfer from sftp-client

1.6k views Asked by At

I am setting a SFTP server on AWS. I am using WinSCP to test it and the files are being transferred to S3 but with some errors:

The server does not support the operation.
Error code: 8
Error message from server (US-ASCII): SETSTAT unsupported

In my lambda, I have this:

exports.lambdaHandler = async (event, context) => {

    let response

    try {
        await sftp.connect({
            host: "myhost",
            port: myport,
            username: process.env.SFTP_USERNAME,
            privateKey: mykey
        })

        let dst = fs.createWriteStream('/tmp/csvStream.csv');

        await sftp.get('/share/csvTest.csv', dst);
        await sftp.end()

        let fileContent = fs.readFileSync('/tmp/csvStream.csv')

        const params = {
            Bucket: "my-bucket",
            Key: 'csvTest.csv',
            Body: fileContent,
            ContentType: 'text/csv',
        }

        let s3UploadPromise = new Promise((resolve, reject) => {
            S3.putObject(params, function (error, data) {
                if (error) {
                    reject(error);
                }
                resolve(`File was Uploaded Successfully. csvTest.csv`)

            });
        })

        let result = await s3UploadPromise

        // const ret = await axios(url);
        response = {
            'statusCode': 200,
            'body': JSON.stringify({
                message: result,
                // location: ret.data.trim()
            })
        }
    } catch (err) {
        console.log(err);
        return err;
    }

    return response
};

And I get:

Invoking app.lambdaHandler (nodejs14.x)
Skip pulling image and use local one: amazon/aws-sam-cli-emulation-image-nodejs14.x:rapid-1.22.0.

Mounting F:\GingerBlack\DataRetriever\Retriever as /var/task:ro,delegated inside runtime container
START RequestId: d1a73d3a-04d7-4b6b-9c95-5bd657211988 Version: $LATEST
} custom: trueeam.Transform._write (internal/streams/transform.js:193:12) {3:15)7:17)99:18) Access denied /share/csvTest.csv
END RequestId: d1a73d3a-04d7-4b6b-9c95-5bd657211988
REPORT RequestId: d1a73d3a-04d7-4b6b-9c95-5bd657211988  Init Duration: 0.13 ms  Duration: 5323.93 ms    Billed Duration: 5400 ms        Memory Size: 128 MB     Max Memory Used: 128 MB
{"code":3,"custom":true}

and files are not being transferred whatsoever.

My s3, the server and the IAM role allow everything for now as I just want to test it, but not sure where that access denied is coming from.

Thank you

1

There are 1 answers

0
Mario Garcia On

My sftp.get was pointing to a wrong location that I had set before when running locally. I just put ./csvTest.csv to fix it.