Search code examples
amazon-web-servicesamazon-s3transfer

How to use AWS Transfer to move a file From AWS to third party using Node.js


I have seen a lot of examples of using AWS Transfer to move files into S3. I have the opposite need.

In a separate project, someone drops a file in S3. I have code that pgp encrypts that file with a third party public key. The code then moves the encrypted file to another S3 location. This part is done and is working.

Problem: I now need to SFTP this S3 encrypted file out of AWS to the third party.

It seems like AWS Transfer is the way to go. The examples I see are all for incoming files.

I would prefer to do this in Lambda. I have a trigger set up in S3 to run a Lambda function every time an encrypted file is dropped. I have that set up and working but nothing else.

Has anyone else done this?


Solution

  • It appears that your requirement is:

    • When a file is placed into a particular Amazon S3 bucket / path
    • Trigger an AWS Lambda function
    • The Lambda function should:
      • Encrypt the file
      • Send it via SFTP to a remote location

    If you have everything working except the last step, then you simply need to write code that will send the file via SFTP. You would place this code in your Lambda function.

    For example, in Node there is a library called ssh2-sftp-client.

    See:

    Since the connection is outbound to a remote location, such a connection would not involve any AWS services (apart from the fact that the code is running within AWS Lambda).